[Haskell-cafe] Re: Exception handling in numeric computations
Henning Thielemann
lemming at henning-thielemann.de
Mon Mar 30 18:03:32 EDT 2009
On Sun, 29 Mar 2009, John Lato wrote:
> On Sat, Mar 28, 2009 at 9:49 PM, Henning Thielemann
> <lemming at henning-thielemann.de> wrote:
>>
>> On Sat, 28 Mar 2009, John Lato wrote:
>>
>>> Honestly, me neither, until recently. I'm only barely starting to
>>> understand it, and I do think there's a great deal of overlap. Even
>>> if an error is a bug that can be fixed by the programmer, certain
>>> exceptional situations can also be fixed by the programmer by handling
>>> the exception, even if they can't be detected in advance.
>>
>> For example?
>
> A file not being written because of a permissions error. This can't
> be detected in advance due to effects from other processes, but it's a
> predictable enough exception that the programmer should handle it for
> IO.
Indeed. However I still do not see the overlap of errors and exceptions.
:-(
Handling of exceptions may mean that you print a message and abort the
affected operation, that is you often do not need a specific exception
handling. E.g. if the user wants to load a file into an editor, and the
file is read-protected, then the editor reports, that the file cannot be
loaded and does not load it. The editor should keep running, in contrast
to when it detects a programming error. The same should happen when the
editor encounters a memory overflow. So I cannot follow the argument of
"memory exhaustion shouldn't happen anymore today, so there is no need to
handle it". I remember this was claimed in this thread, too. However,
recovering from a memory exhaustion can be tricky. Can the garbage
collector still free memory, when it cannot allocate memory temporarily?
>> Btw. not handling an exception is an error.
>
> Agreed generally. But some exceptions are likely in given contexts,
> others are not. I don't think it's necessary to handle every possible
> exception, just the ones that are likely and predictable for a given
> activity.
Since handling of exceptions often consist of reporting the exception and
aborting an operation, it should always be managable to handle all
possible exceptions.
> Excluding generic "The impossible happened, file a bug report"
> handlers.
This is the one special case, where program errors are catched in order to
allow debugging.
More information about the Haskell-Cafe
mailing list