[Haskell-cafe] Correct way to "catch all exceptions"

Michael Snoyman michael at snoyman.com
Fri Jul 12 15:24:12 CEST 2013


When I implemented this stuff yesterday, I included `Deep` variants for
each function which used NFData. I'm debating whether I think the right
recommendation is to, by default, use the `async`/NFData versions of catch,
handle, and try, or to have them as separate functions.

I wrote up the blog post, both on the Yesod blog[1] and School of
Haskell[2]. The latter's a bit easier to use since it includes active code
snippets.

[1] http://www.yesodweb.com/blog/2013/07/catching-all-exceptions
[2]
https://www.fpcomplete.com/user/snoyberg/general-haskell/exceptions/catching-all-exceptions


On Fri, Jul 12, 2013 at 4:03 AM, John Lato <jwlato at gmail.com> wrote:

> I agree that how the exception was thrown is more interesting than the
> type.  I feel like there should be a way to express the necessary
> information via the type system, but I'm not convinced it's easy (or even
> possible).
>
> Another issue to be aware of is that exceptions can be thrown from pure
> code, so if you don't fully evaluate your return value an exception can be
> thrown later, outside the catch block.  In practice this usually means an
> NFData constraint, or some other constraint for which you can guarantee
> evaluation.
>
> In the past I've been pretty vocal about my opposition to exceptions.
>  It's still my opinion that they do not make it easy to reason about
> exceptional conditions.  Regardless, as Haskell has them and uses them, I'd
> like to see improvements if possible.  So if anyone is exploring the design
> space, I'd be willing to participate.
>
>
> On Fri, Jul 12, 2013 at 12:57 AM, Michael Snoyman <michael at snoyman.com>wrote:
>
>>
>>
>>
>> On Thu, Jul 11, 2013 at 6:07 PM, Felipe Almeida Lessa <
>> felipe.lessa at gmail.com> wrote:
>>
>>> On Thu, Jul 11, 2013 at 10:56 AM, Michael Snoyman <michael at snoyman.com>
>>> wrote:
>>> > The only
>>> > approach that handles the situation correctly is John's separate thread
>>> > approach (tryAll3).
>>>
>>> I think you meant "tryAll2" here.  Got me confused for some time =).
>>>
>>> Cheers,
>>>
>>> --
>>> Felipe.
>>>
>>
>> Doh, yes, I did, thanks for the clarification.
>>
>> After playing around with this a bit, I was able to get an implementation
>> of try, catch, and handle which work for any non-async exception, in monad
>> transformers which are instances of MonadBaseControl (from monad-control).
>> I'll try to write up my thoughts in something more coherent, likely a blog
>> post.
>>
>> Michael
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130712/2c7fdb59/attachment.htm>


More information about the Haskell-Cafe mailing list