ResultTypes.jl
ResultTypes.jl copied to clipboard
Add macro for throwing exceptions
I think this is really a great package!
Although I prefer to use ResultTypes
over plain Julia exceptions in most situations,
in some cases I still want to throw exceptions rather than propagate the Result
using @try
.
Therefore I added another macro called @throw
.
Example:
foo(i::Int)::Result{Int,ArgumentError} = i ≥ 0 ? i : ArgumentError("negative `i`")
result = @throw(foo(1))
@assert result == 1
result = @throw(foo(-1)) # throws `ArgumentError`
Maybe you agree that this would be a convenient addition to your package! Please let me know if I can improve upon my proposed contribution. Thanks.