-import qualified System.IO.Error as H'98 (catch)
-import System.IO.Error (ioError)
-import IO (bracket)
-import DIOError -- defn of IOError type
-import System (ExitCode())
-
--- minimum needed for nhc98 to pretend it has Exceptions
-data Exception = IOException IOException
- | ArithException ArithException
- | ArrayException ArrayException
- | AsyncException AsyncException
- | ExitException ExitCode
- deriving Show
-type IOException = IOError
-data ArithException
-data ArrayException
-data AsyncException
-instance Show ArithException
-instance Show ArrayException
-instance Show AsyncException
-
-catch :: IO a -> (Exception -> IO a) -> IO a
-a `catch` b = a `H'98.catch` (b . IOException)
-
-throwIO :: Exception -> IO a
-throwIO (IOException e) = ioError e
-throwIO _ = ioError (UserError "Control.Exception.throwIO"
- "unknown exception")
-throw :: Exception -> a
-throw = unsafePerformIO . throwIO
-
-evaluate :: a -> IO a
-evaluate x = x `seq` return x
-
-ioErrors :: Exception -> Maybe IOError
-ioErrors (IOException e) = Just e
-ioErrors _ = Nothing
-arithExceptions :: Exception -> Maybe ArithException
-arithExceptions (ArithException e) = Just e
-arithExceptions _ = Nothing
-errorCalls :: Exception -> Maybe String
-errorCalls = const Nothing
-dynExceptions :: Exception -> Maybe Dynamic
-dynExceptions = const Nothing
-assertions :: Exception -> Maybe String
-assertions = const Nothing
-asyncExceptions :: Exception -> Maybe AsyncException
-asyncExceptions = const Nothing
-userErrors :: Exception -> Maybe String
-userErrors (IOException (UserError _ s)) = Just s
-userErrors _ = Nothing
-
-assert :: Bool -> a -> a
-assert True x = x
-assert False _ = throw (IOException (UserError "" "Assertion failed"))
-#endif
-
-#ifndef __GLASGOW_HASKELL__
--- Dummy definitions for implementations lacking asynchonous exceptions
-
-block :: IO a -> IO a
-block = id
-unblock :: IO a -> IO a
-unblock = id
-blocked :: IO Bool
-blocked = return False
-#endif
-
------------------------------------------------------------------------------
--- Catching exceptions
-
--- |This is the simplest of the exception-catching functions. It
--- takes a single argument, runs it, and if an exception is raised
--- the \"handler\" is executed, with the value of the exception passed as an
--- argument. Otherwise, the result is returned as normal. For example:
---
--- > catch (openFile f ReadMode)
--- > (\e -> hPutStr stderr ("Couldn't open "++f++": " ++ show e))
---
--- For catching exceptions in pure (non-'IO') expressions, see the
--- function 'evaluate'.
---
--- Note that due to Haskell\'s unspecified evaluation order, an
--- expression may return one of several possible exceptions: consider
--- the expression @error \"urk\" + 1 \`div\` 0@. Does
--- 'catch' execute the handler passing
--- @ErrorCall \"urk\"@, or @ArithError DivideByZero@?
---
--- The answer is \"either\": 'catch' makes a
--- non-deterministic choice about which exception to catch. If you
--- call it again, you might get a different exception back. This is
--- ok, because 'catch' is an 'IO' computation.
---
--- Note that 'catch' catches all types of exceptions, and is generally
--- used for \"cleaning up\" before passing on the exception using
--- 'throwIO'. It is not good practice to discard the exception and
--- continue, without first checking the type of the exception (it
--- might be a 'ThreadKilled', for example). In this case it is usually better
--- to use 'catchJust' and select the kinds of exceptions to catch.
---
--- Also note that the "Prelude" also exports a function called
--- 'Prelude.catch' with a similar type to 'Control.Exception.catch',
--- except that the "Prelude" version only catches the IO and user
--- families of exceptions (as required by Haskell 98).
---
--- We recommend either hiding the "Prelude" version of 'Prelude.catch'
--- when importing "Control.Exception":
---
--- > import Prelude hiding (catch)
---
--- or importing "Control.Exception" qualified, to avoid name-clashes:
---
--- > import qualified Control.Exception as C
---
--- and then using @C.catch@
---
-#ifndef __NHC__
-catch :: IO a -- ^ The computation to run
- -> (Exception -> IO a) -- ^ Handler to invoke if an exception is raised
- -> IO a
-catch = ExceptionBase.catchException