Follow changes in the base library
[ghc-hetmet.git] / compiler / utils / Exception.hs
1
2 module Exception
3     (
4     module Control.Exception,
5     module Exception
6     )
7     where
8
9 import Prelude hiding (catch)
10 import Control.Exception
11
12 #if __GLASGOW_HASKELL__ < 609
13 type SomeException = Exception
14
15 onException :: IO a -> IO () -> IO a
16 onException io what = io `catch` \e -> do what
17                                           throw e
18 #endif
19
20 catchIO :: IO a -> (IOException -> IO a) -> IO a
21 #if __GLASGOW_HASKELL__ >= 609
22 catchIO = catch
23 #else
24 catchIO io handler = io `catch` handler'
25     where handler' (IOException ioe) = handler ioe
26           handler' e                 = throw e
27 #endif
28
29 handleIO :: (IOException -> IO a) -> IO a -> IO a
30 handleIO = flip catchIO
31
32 tryIO :: IO a -> IO (Either IOException a)
33 #if __GLASGOW_HASKELL__ >= 609
34 tryIO = try
35 #else
36 tryIO io = do ei <- try io
37               case ei of
38                   Right v -> return (Right v)
39                   Left (IOException ioe) -> return (Left ioe)
40                   Left e -> throwIO e
41 #endif
42