[Haskell-cafe] Extensible Exceptions
nominolo at googlemail.com
Sat Nov 22 18:25:06 EST 2008
It's a pattern match error, implemented by throwing an asynchronous
exception. The idea being, that we only have one mechanism (well, an
synchronous exceptions, thrown via throwIO).
Yes, I know that there's a difference between "error" and "exception",
but I would argue that which is which depends on the program. For
example, for most programs a pattern match error is a fatal condition,
there's no sane recovery from it. OTOH, in a program like GHCi, a
pattern match error in an executed statement is an exceptional
condition, which we want to catch, so it doesn't kill GHCi.
2008/11/22 Henning Thielemann <lemming at henning-thielemann.de>:
> On Sat, 22 Nov 2008, Thomas Schilling wrote:
>> Be careful, though. This only works if there's a single constructor
>> for your exception type. If there are multiple, you should write it
>> like this:
>> thing_to_try `catch` \(e :: MyErrorType) -> case e of MyError1 _ ->
>> ..; MyError2 _ -> ...
>> If you write `catch` (MyError1 ...) and a MyError2 is thrown, you will
>> get a pattern match error exception.
> A "pattern match exception" or "pattern match error"? I mean, not handling a
> certain pattern is a programming error not an exceptional condition at
> runtime. Thus there is no need to throw a "pattern match exception" which is
> catched and handled somewhere else.
Push the envelope. Watch it bend.
More information about the Haskell-Cafe