[Haskell-cafe] Extensible Exceptions

Thomas Schilling nominolo at googlemail.com
Sat Nov 22 06:33:31 EST 2008


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.

If you want to catch multiple exceptions (of different type) at once,
use the "catches" combinator.

2008/11/22 Ross Mellgren <rmm-haskell at z.odi.ac>:
> I think catch is now basically what catchJust was -- you can just do
>
>> thing_to_try `catch` (\ (ErrorCall s) -> putStrLn s)
>
> and it will only catch ErrorCall exceptions.
>
> -Ross
>
>
> David F. Place wrote:
>>
>> Hi, All.
>>
>> I am trying to understand the new exceptions package in base-4
>> Control.Exceptions.  The documentation for catchJust is the same as in
>> Control.OldException including this example:
>>
>> result <- catchJust errorCalls thing_to_try handler
>>
>> Control.OldException provides the predicate errorCalls, but the new one
>> does not.  I don't see how to write it.
>>
>> Thanks for reading.
>>
>> Cheers,
>> David
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Push the envelope.  Watch it bend.


More information about the Haskell-Cafe mailing list