nlkl / Optional

A robust option type for C#
MIT License
903 stars 73 forks source link

Usafe method to turn Option<T, TException> to Option<T> while throwing TException #42

Closed Euphoric closed 6 years ago

Euphoric commented 7 years ago

Sometimes, exception is not a bad thing. A code within library could return Option<T, TException>, but the exception cannot be properly handled in calling code, so just fall-back to C# exception handling by throwing this exception like normally using unsafe method.

One problem is that TException can be of any type and not just Exception. My suggestion is : If TException is Exception, then throw InvalidOperationException (or something similar) and exception as inner exception. If it isn't Exception, then create new Exception type and save the exception as object within it.

Euphoric commented 7 years ago

Actually. I just realized this is stupid suggestion. It would work if the Option<T, TException> was tri-state : value, null or exception. Which it is not.

You can close this then.