Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#13348 closed feature request (wontfix)

Consider making throw and throwIO strict

Reported by: dfeuer Owned by:
Priority: normal Milestone: 8.4.1
Component: Core Libraries Version: 8.1
Keywords: Exceptions Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

It's possible for code to throw an exception that itself throws an imprecise exception. Such an exception is tricky to catch. For example:

import Control.Exception

strange = throwIO (undefined :: SomeException) `catch` \ex ->
  case () of
    _ | Just _ <- (fromException ex :: Maybe IOError) -> print "IOError"
      | otherwise -> print "Something else"

You might think that this would catch the exception and print "Something else", but in fact it does not. If others think this is as surprising as I do, perhaps we should make throwIO and throw strict, so an exception will never itself be bottom. Using

throwIO' !e = throwIO e

in the code above instead of throwIO allows the exception to be caught.

Change History (2)

comment:1 Changed 3 years ago by dfeuer

Resolution: wontfix
Status: newclosed

Eric Mertens has given a reasonable argument against this.

comment:2 Changed 3 years ago by simonpj

Keywords: Exceptions added
Note: See TracTickets for help on using tickets.