haskell-handbook icon indicating copy to clipboard operation
haskell-handbook copied to clipboard

[New topic] Errors and exceptions

Open Martinsos opened this issue 4 years ago • 5 comments
trafficstars

Martinsos avatar May 04 '21 13:05 Martinsos

lhbg-book.link has a few chapters on Either, ExceptT, and exceptions.

soupi avatar Nov 04 '21 08:11 soupi

Thanks for sharing, I find especially interesting the one about exceptions since I still I need to understand that part better!

What are your thoughts about recommendation from https://www.fpcomplete.com/haskell/tutorial/exceptions/ to use UnliftIO.Exception instead of Control.Exception?

Martinsos avatar Nov 08 '21 14:11 Martinsos

I believe fpco understand exceptions better than me. I've tried covering the basics that are available in base and focus on IO. It is also likely that understanding the regular Control.Exception will make using UnliftIO.Exception easier anyway, because they have very similar APIs and concepts.

soupi avatar Nov 08 '21 17:11 soupi

What is also somewhat confusing is when to use Either vs throwing an IO exception. Interesting discussion here: https://www.reddit.com/r/haskell/comments/z5ezoa/why_network_requests_throw_exceptions_instead_of/ .

The summary is somewaht in direction of: use Either when you want consumer of function to be very aware of what you are returning and explicitly handle it, vs use IO exception when you want to be more implicit and just let him handle those exceptions only if they really want to. But I don't think this is final explanation, I think there is more to it, this was just what I quickly got from it.

Martinsos avatar Jan 15 '23 15:01 Martinsos

As a general approach when following the 'functional core, imperative shell' pattern, I usually use Either/Except in the functional core, and exceptions in the imperative shell.

soupi avatar Mar 22 '23 08:03 soupi