[Haskell-cafe] Re: Exception handling in numeric computations
Henning Thielemann
lemming at henning-thielemann.de
Sat Mar 28 16:33:42 EDT 2009
On Sat, 28 Mar 2009, 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).
In C++ you can either throw exceptions or return integer codes in order to
show exceptional situations. An error is, if you write in non-allocated
memory areas.
> So, I'll ask again: when I program in Haskell, what mechanism should I use?
I think this question was enough answered in general here in the thread
and on the Wiki pages. I think we can better discuss concrete situations.
Do you have a function in your code where you are uncertain whether to use
error or exceptions?
More information about the Haskell-Cafe
mailing list