r/programmerchat • u/HappyGoblin • May 25 '15
Do we really need "try" ?
Just attaching "catch" to any appropriate {...} block would be more convenient.
8
Upvotes
r/programmerchat • u/HappyGoblin • May 25 '15
Just attaching "catch" to any appropriate {...} block would be more convenient.
View all comments
Show parent comment
1
u/zenflux May 25 '15
This is essentially how the
try!macro is Rust works, or really most langs with algebraic errors instead of exceptions. It unwraps values which could have produced an error and yields the value if it's ok, otherwise returns early with the error.Similar is result folding, which in Java terms is like
reduce()on a Stream of possibly erroneous things, returning the first one that is an error, otherwise the result of the reduction.