On Fri, Apr 26, 2013 at 2:29 AM, Brian Anderson <[email protected]>wrote:
> It's almost taboo here, but we could consider adding catchable exceptions.
>
...which would let you default to the failing/throwing versions of
functions, and allow (or obviate) an efficient translation to
Result/Option. (Though: the None/Err cases would presumably still be slower
than a direct implementation, exception handling isn't typically considered
a fast path either. Is there a use case where that's a problem?)
I don't know how I feel about the prospect of catchable exceptions. Is
there a way to do them that doesn't suck? (i.e. other than how C++ or Java
do them)
The other direction would be some kind of syntax sugar to make interacting
with Options/Results seamless (less seamful), but I have no idea how that
might look.
I was only thinking that instead of
condition! { io_error: super::IoError -> (); }
you might have
condition! { file_not_found_error: super::FileNotFoundError -> Foo; }
condition! { file_permission_error: super::FilePermissionError -> Bar; }
and so forth. In other words, instead of the branching in the IoError
enum, branching at the condition and error-describing-type level. That only
makes sense in the as-you-would-expect-a-condition-system-to-work scenario
though.
This is attractive, but how could you then create a block of code that
> trapped *all* errors?
>
Good question. That would only make sense if there's also a uniform way to
recover from all the errors. I think you could do it by making a
trap()/cond()-like that takes a fn(IoError) -> RecoveryType (where IoError
is an enum wrapping all of the specialized error types), installs condition
handlers for all of the specific conditions, and delegates all of them to
the general IoError-handling closure. So yeah, you'd still have a big
IoError enum, but you would only have to deal with it if you really did
want to handle all of the possibilities.
--
Your ship was destroyed in a monadic eruption.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev