[Haskell] IO, exceptions and error handling
Alastair Reid
alastair at reid-consulting-uk.ltd.uk
Mon Jun 14 12:57:46 EDT 2004
> I assume the suggested mapException function [sect 5.4] remains
> unproblematic ... is it (or some equivalent) actually implemented?
http://etudiants.insia.org/~jbobbio/pafp/docs/base/Control.Exception.html#v%
3AmapException
The same page has a host of other useful operations.
Two useful capabilities that are missing in the actual implementation are:
1) Provision for routinely adding filename and line number.
(Of course, we'd need some kind of compiler support for filling
that info in.)
data Exception = ... | Location SrcLoc Exception | ...
2) The ability to build up lists of exceptions perhaps by adding something
like:
data Exception = ... | Nested Exception Exception | ...
This would allow handlers to build 'stacks' of exceptions rather like the
stackdumps Java exceptions produce. For example:
foo x = mapException (Nested (ErrorCall "while in foo")) $ bar x
bar x = mapException (Nested (ErrorCall "while in bar")) $ baz x
baz x = 1/x
foo 0
==>
Nested (ErrorCall "while in foo")
(Nested (ErrorCall "while in bar")
(ArithException DivideByZero))
[Alternate names for 'Nested' welcome. `WhileDoing` is my next best
attempt :-)]
--
Alastair Reid
More information about the Haskell
mailing list