[Haskell-cafe] Exception handling when using STUArray

Henning Thielemann lemming at henning-thielemann.de
Sun Mar 9 16:07:58 EDT 2008

On Sat, 8 Mar 2008, Donn Cave wrote:

> On Mar 8, 2008, at 12:33 PM, Henning Thielemann wrote:
> > On Sat, 8 Mar 2008, Denis Bueno wrote:
> ...
> >> I am also using STUArray from some time-critical code; however, I
> >> don't deal with ArrayException, or any exceptions for that matter.
> >> What besides an out-of-bounds read or write might throw an
> >> ArrayException?  If it is out-of-bounds reading or writing, surely
> >> that indicates a bug in your program that you'd rather fix than catch
> >> the exception, no?
> >
> > Another instance of mixing up exceptions and errors in the Haskell
> > libraries.
> >   http://www.haskell.org/haskellwiki/Error
> >   http://www.haskell.org/haskellwiki/Exception
> This seems to me one of the disappointments of Haskell - not just a
> detail that was handled in an awkward way, but a fundamental flaw.
> I'm not talking about ArrayException, whatever that is, but the notion
> that errors encountered in functional code mustn't be handled as
> exceptions.

Errors are programming errors and must be fixed as Denis explained. Thus
there is no need for a complex system of handling these situations at
run-time. The program error might be unexpected but it isn't the fault of
the user or of the context the program runs in but of the fault of the
programmer. The program may report "bug detected, send an e-mail to the
author" but eventually it should quit (at least the buggy thread) before
worse things happen. This is possible in Haskell but should not be mixed
up with handling of exceptions like "non-existing file".

> I rejoice that Haskell isn't as miserable as C, but with respect to
> exceptions and errors, it's behind for example Python.  Languages that
> can, use exceptions like IndexError.

How precisely would you handle IndexError if it would be an exception and
not just an error?

More information about the Haskell-Cafe mailing list