[Haskell-cafe] Errors in non-monadic code

jabolopes at google.com jabolopes at google.com
Mon Aug 19 23:15:39 CEST 2013


I agree that whether to use exceptions or not is a very debatable
subject and it is a grey area.

Still, in your Python example, I would like to point out that just
because something is common, it does not mean it is the right thing to
do.  For example, something that some Java programmers were doing a
lot was to loop through an array and, instead of using a counter, they
were catching the array out of bounds exception. This is clearly not
the right thing to do!

But I would like to see more code move away from exceptions and into
types like "Maybe" or "Either" or other types defined for the
particular situation (as some people were suggesting in the beginning
of the thread). And the reason for this it is because when you program
against types you have to make a decision whether to handle the error
or let it bleed through: you can't ignore the choice because you can't
ignore the type. On the other hand, with exceptions, you can easily
forget to handle the exception if you're not looking at the
documentation at the time when you write the code.

Jose

On Mon, Aug 19, 2013 at 01:12:13PM -0700, Donn Cave wrote:
> jabolopes at google.com,
> MIME-Version: 1.0
> Content-type: text/plain; charset=UTF-8
> In-Reply-To: <CAKFCL4VfY-Dz3Xo9ZUZ_SmfRQ2nLGDLbovU=SuF1-sSnqVS8Hw at mail.gmail.com>
> References: <CAKFCL4VfY-Dz3Xo9ZUZ_SmfRQ2nLGDLbovU=SuF1-sSnqVS8Hw at mail.gmail.com>
> 
> quoth Brandon Allbery,
> 
> > Even in IO, exceptions should be reserved for truly exceptional conditions
> > (of the "program cannot safely continue" variety), not merely for error
> > checking when this can be described as a normal flow of evaluation.
> > Exceptions are not simply alternative flow of control, even in procedural
> > languages; they are *disruptions* of flow of control.
> 
> I think that would be debatable, especially as applied to procedural languages
> in general.  It's very common to use exceptions in routine flow of control in
> Python programs, if I remember right.  Meanwhile, the Haskell library in my
> opinion somewhat weakens your case by making ordinary conditions into exceptions,
> for example end-of-file.  
> 
> In the end it's a large grey area.  Ideally, what the program has to do, or
> whether it can even continue at all, is determined by the program using
> information reported by the function that encounters the error.  If there's
> a good reason why exceptions should be used only when the program won't be
> able to continue, it must be that the language's exception handling facililty
> isn't very robust.
> 
> 	Donn
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe




More information about the Haskell-Cafe mailing list