X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FException.hs;h=a316c56ba528745a41af38c4098ebf55ba95e5ee;hb=bbc583766a08678d03740354bed216e268306356;hp=11172b59b176e95fa28def02d02d7013d29378f8;hpb=aa9a4f1053d3c554629a2ec25955e7530c95b892;p=ghc-hetmet.git diff --git a/compiler/utils/Exception.hs b/compiler/utils/Exception.hs index 11172b5..a316c56 100644 --- a/compiler/utils/Exception.hs +++ b/compiler/utils/Exception.hs @@ -1,19 +1,42 @@ module Exception ( + module Control.Exception, + module Exception + ) + where + +import Prelude hiding (catch) +import Control.Exception + +#if __GLASGOW_HASKELL__ < 609 +type SomeException = Exception + +onException :: IO a -> IO () -> IO a +onException io what = io `catch` \e -> do what + throw e +#endif + +catchIO :: IO a -> (IOException -> IO a) -> IO a #if __GLASGOW_HASKELL__ >= 609 - module Control.OldException +catchIO = catch #else - module Control.Exception +catchIO io handler = io `catch` handler' + where handler' (IOException ioe) = handler ioe + handler' e = throw e #endif - ) - where -import Prelude () +handleIO :: (IOException -> IO a) -> IO a -> IO a +handleIO = flip catchIO +tryIO :: IO a -> IO (Either IOException a) #if __GLASGOW_HASKELL__ >= 609 -import Control.OldException +tryIO = try #else -import Control.Exception +tryIO io = do ei <- try io + case ei of + Right v -> return (Right v) + Left (IOException ioe) -> return (Left ioe) + Left e -> throwIO e #endif