[Haskell-cafe] Exception handling when using STUArray

Don Stewart dons at galois.com
Sun Mar 9 01:54:24 EST 2008

> 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.
> If your input file is not where you expected it and openFile fails,  
> or it was
> incompletely written out and your input processing fails in a 'head' or
> pattern match, the difference is not very important to me.  I want to be
> able to call your code and manage the risk that it's going to kill my  
> server.
> You may feel that it's your job to write more robust functional code  
> that
> can't run into these errors, but C programmers can be found who insist
> that it's the programmer's job to manage heap memory and it isn't all
> that hard.  A programming language that fails to make it easier to write
> more robust code, is not moving us forward.  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.
> Evidently, Haskell fundamentally can't.  That's too bad.

I don't understand this complaint -- you can handle all these with Control.Exception.

xmonad catches all these things for example, in user code, to prevent
poorly written modules throwing a pattern match exception, or calling
'error' and making the window manager unstable.

Handling exceptions generated from pure code is just another part of
making systems more robust -- and of course you can do it in Haskell.

-- Don

More information about the Haskell-Cafe mailing list