API

ResultTypes API

Constructors

Result(val::T, exception_type::Type{E}=Exception) -> Result{T, E}

Create a Result that could hold a value of type T or an exception of type E, and store val in it. If the exception type is not provided, the supertype Exception is used as E.

source
ErrorResult(::Type{T}, exception::E) -> Result{T, E}
ErrorResult(::Type{T}, exception::AbstractString="") -> Result{T, ErrorException}

Create a Result that could hold a value of type T or an exception of type E, and store exception in it. If the exception is provided as text, it is wrapped in the generic ErrorException. If no exception is provided, an ErrorException with an empty string is used. If the type argument is not provided, Any is used.

ErrorResult is a convenience function for creating a Result and is not its own type.

source

Functions

ResultTypes.unwrapFunction.
unwrap(result::Result{T, E}) -> T
unwrap(val::T) -> T
unwrap(::Type{T}, result_or_val) -> T

Assumes result holds a value of type T and returns it. If result holds an exception instead, that exception is thrown.

If unwrap's argument is not a Result, it is returned.

The two-argument form of unwrap calls unwrap on its second argument, then converts it to type T.

source
unwrap_error(result::Result{T, E}) -> E
unwrap_error(exception::E) -> E

Assumes result holds an exception of type E and returns it. If result holds a value instead, throw an exception.

If unwrap_error's argument is an Exception, that exception is returned.

source
ResultTypes.iserrorFunction.
ResultTypes.iserror(x) -> Bool

If x is an Exception, return true. If x is an ErrorResult (a Result containing an Exception), return true. Return false in all other cases.

source