[Haskell-cafe] Re: Exception handling in numeric computations

Jonathan Cast jonathanccast at fastmail.fm
Sun Mar 29 10:53:47 EDT 2009


On Sat, 2009-03-28 at 12:51 +0300, Gregory Petrosyan wrote:
> On Sat, Mar 28, 2009 at 10:53 AM, Ketil Malde <ketil at malde.org> wrote:
> > So the difference between an exception or an error type is mainly what
> > you intend to do about it.  There's no point in wrapping divisions in
> > Maybe unless you actually are able to do something useful to recover
> > from a zero denominator.
> 
> That is exactly the point I was trying to make.
> 
> When I write a code, I can't say in advance, in what way it will be used.
> So, for dealing with errors, I have to choose one way or another, mostly
> without that knowledge. When I'm using e.g. C++, it's easy:
> something like mantra "when in doubt, throw an exception" :-)
> combined with RAII, works good (but not ideal, of course).
> 
> So, I'll ask again: when I program in Haskell, what mechanism should I use?

If you don't know, use a (true) exception.  That is, Left or Exception
or throwIO.

Only use error or throw when you *know* the condition is un-recoverable.

jcc




More information about the Haskell-Cafe mailing list