[Haskell] Catching error / making library functions monadic (in failure)

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Oct 8 11:28:19 EDT 2008


On Wed, 2008-10-08 at 16:58 +0200, Philip K.F. Hölzenspies wrote:

> Is there any way to catch errors in functions in libraries (like the
> Prelude)?

Yes. Use Control.Exception.catch

The catch in the Prelude is only for catching IO errors. It cannot catch
errors thrown from pure code. Note that you can only catch exceptions in
IO.

> I use quite a few functions that produce errors (also from gtk2hs).
> These functions have been programmed using "error." Would these
> functions have been programmed with "abort," all would be honkey-dory.

Which gtk2hs functions that you're using use error? It would be
interesting to know which ones are a problem. I thought gtk2hs mostly
throws exceptions in IO (which can be caught in IO) except for some rare
cases which would always be programming errors.

If you can report them we can fix them.

Duncan



More information about the Haskell mailing list