[Haskell-cafe] Correct way to "catch all exceptions"
hesselink at gmail.com
Wed Jul 10 11:02:28 CEST 2013
On Wed, Jul 10, 2013 at 10:39 AM, John Lato <jwlato at gmail.com> wrote:
> I think 'shouldBeCaught' is more often than not the wrong thing. A
> whitelist of exceptions you're prepared to handle makes much more sense than
> excluding certain operations. Some common whitelists, e.g. filesystem
> exceptions or network exceptions, might be useful to have.
You'd think that, but there are common use cases. For example, if you
have a queue of work items, and a thread (or threads) processing them,
it is useful to catch all exceptions of these threads. You can then
log the exception, remove the item from the queue and put it in some
error bucket, and continue on to the next item. The same goes for e.g.
socket listening threads etc.
The thing here is that you are *not* actually handling the specific
exception, but instead failing gracefully. But you still want to be
able to kill the worker threads, and you don't want to handle
exceptions that you cannot recover from even by moving on to the next
More information about the Haskell-Cafe