Skip to content

Consider making throw and throwIO strict

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.

Trac metadata
Trac field Value
Version 8.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information