On Error Handling in Rust
lucumr.pocoo.org
On Error Handling in Rust
1–10 of 82 posts
Re: On Error Handling in Rust
#2Microsoft's upcoming M# language has also teased an interesting approach to error-handling. I'm very curious to see what they come up with.
Re: On Error Handling in Rust
#3Re: On Error Handling in Rust
#4This makes it very easy to tell whether code is handling potential failure conditions or ignoring them - you're either ignoring the return value (which is a compiler warning) or you're handling the failure condition. I'm reminded of Raymond Chen's post from 2005 about handling failure conditions, and recognizing code which handles all of its error conditions:
http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/35294...
I think this approach will pay great dividends in both understandability and readability.
Re: On Error Handling in Rust
#5Re: On Error Handling in Rust
#6Re: On Error Handling in Rust
#7[1] https://github.com/glaebhoerl/rfcs/blob/trait-based-exceptio...
Re: On Error Handling in Rust
#8So it's a specialized mapping operator for the Result functor. Why restrict it to Result only? What about using option to denote a failure condition without a specific reason? Or other kinds of interesting functors?
https://github.com/glaebhoerl/rfcs/blob/trait-based-exceptio...
Re: On Error Handling in Rust
#9The nicest things about error handling in this manner are that any function that has a error condition makes it clear in the function signature, and any time you call a function that can fail, it's visible in the source where you make the call. This makes it very easy to tell whether code is handling potential failure conditions or ignoring them - you're either ignoring the return value (which is a compiler warning)…
In case my comment is taken as denigration, I'm saying this from a perspective of admiration. I think this is a fairly elegant way to solve a difficult problem, and learning Rust has been a true pleasure. I'm excited for the future of the language.
Re: On Error Handling in Rust
#10I did this in Haskell using MPTC, I have used the Convertible class like:
instance Convertible IOError RedisError where safeConvert =
Then I have combinators like:
convEither :: Convertible e1 e2 => Either e1 a -> Either e2 a
and
convEitherT :: Convertible e1 e2 => m (Either e1 a) -> EitherT m e2 a
These are quite handy in close quarters combat. For example to open a file and bail on a generic IOException with a custom application exception, I can have something like:
instance Convertible IOException CustomError
getWords :: FilePath -> IO (Either CustomError [String])
getWords fileName = runEitherT $
do file >= convEitherT
line