[Haskell-cafe] Re: New Hackage category: Error Handling
lemming at henning-thielemann.de
Mon Dec 7 07:13:00 EST 2009
Michael Snoyman schrieb:
> On Mon, Dec 7, 2009 at 5:30 AM, Ben Franksen <ben.franksen at online.de
> <mailto:ben.franksen at online.de>> wrote:
> Michael Snoyman wrote:
> > On the other hand, what's so bad about treating errors as exceptions? If
> > instead of the program crashing on an array-out-of-bound or pattern-match
> > it throws an exception which can be caught, so what?
> The error gets hidden instead of fixed?
> You're right; bad programmers could do this. A good programmer will know
> to do one of two things when it gets an exception it does not know how
> to handle:
It is certainly not the task of a programming language or a library to
parent its users. Despite an interesting idea, it will not work, since
programmers will simply switch to a different language or library if
they feel pushed around.
There is an important reason to not simply catch an error and proceed as
if it were only an exception: The error might have corrupted some data
and there is no general way to recover from that. Say, after detecting
an error you might want to close a file that you were working on. But
since you are coping with an error, something you did not foresee, you
cannot tell whether the file was already closed again or never opened.
So it is better to just abort the program.
The next higher level, the shell calling your program or the browser
calling your plugin, might have registered what have opened and
allocated and can reliably free those resources.
More information about the Haskell-Cafe