[Haskell-cafe] Exceptions

MR K P SCHUPKE k.schupke at imperial.ac.uk
Fri Oct 1 11:57:52 EDT 2004

>1. Can exceptions be used in "pure" functions (outside of monads?)

Exceptions can be thrown from pure functions, and can be used exactly
like in the OCaml example (but in Haskell syntax)

Exceptions can only be caught in the IO monad.

>2. How are these exceptions caught and handled aside from using bracket?

bracket, catch, catchIO 

>3. Can I define my own exception types?

There is a User exception type, I don't think you can define your own
completely new exception type.

>4. Can I write code that can catch and handle multiple different
>exception types from a single block of code?

Yes but see (1) only in the IO monad

>5. Is there anything different about working with exceptions in monads?


>6. Can I get a stack trace from ghc or hugs if an exception is never
>caught and thus causes the program to terminate?

Stack traces in lazy laguages are not very useful. Best work-around is
to produce an explicit call trace by inserting prints into functions...
obviously this requires the functions to be in the IOMonad. Things are
still odd because of lazyness though.


More information about the Haskell-Cafe mailing list