OptTThrowIfNone Method

Overload List

ThrowIfNone Returns the option back when IsSome; throws a NullReferenceException when IsNone. Can be called without breaking the flow of chained operations.
C#
var interestRate = GetOptionalUser(input)
    .ThrowIfNone("failed to get the user")
    .Map(user => ComputeInterestRate(user))
    .Unwrap();
ThrowIfNone(String) Returns the option back when IsSome; throws a NullReferenceException when IsNone. Appends the errorMessage to the exception if the message IsSome. Can be called without breaking the flow of chained operations.
C#
var interestRate = GetOptionalUser(input)
    .ThrowIfNone("failed to get the user")
    .Map(user => ComputeInterestRate(user))
    .Unwrap();
ThrowIfNoneE(FuncE) Returns the option back when IsSome; throws a custom exception when IsNone. Exception thrown when IsNone is created by the provided method getException. Can be called without breaking the flow of chained operations.
C#
var interestRate = GetOptionalUser(input)
    .ThrowIfNone(() => new ArithmeticException("sth went wrong"))
    .Map(user => ComputeInterestRate(user))
    .Unwrap();

See Also