[Haskell-cafe] Decorating exceptions with backtrace information

Henning Thielemann lemming at henning-thielemann.de
Tue May 12 21:06:35 UTC 2020


On Fri, 8 May 2020, Ben Gamari wrote:

> We can debate whether partial functions like `fromJust` should exist; however,
> the fact of the matter is that they do exist and they are used.

That's not my point. I say: fromJust on Nothing is a programming error, 
ok. We must debug this. HasCallStack helps here. However, it does not have 
to do with exceptions or with the proposals as I understand them.

> Furthermore, even `base`'s own IO library (e.g. `openFile`) uses
> synchronous exceptions to report errors.

Right. I say: Such exceptions are part of the public interface and should 
be expressed in types. If you encounter any problems when not doing this, 
I would first try to solve the problem with exceptions explicit in the 
type. E.g. Haddock for openFile says:

This operation may fail with:

* isAlreadyInUseError ...
* isDoesNotExistError ...
* isPermissionError ...

Thus the type should be:

openFile ::
    (AlreadyInUseException e,
     DoesNotExistException e,
     PermissionException e) =>
    FilePath -> IOMode -> ExceptT e IO Handle


> Perhaps this helps to shed some light on the motivation?

Unfortunately no. I only see the immortal confusion about (programming) 
errors vs. (IO) exceptions. And I think that part of this confusion is 
that IO exceptions in 'base' are hidden in the IO type and that there are 
hybrid functions like 'throw' that can be called like 'error' but they 
cause IO exceptions that can be caught by 'catch'.


More information about the Glasgow-haskell-users mailing list