-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())
-import System.IO.Unsafe (unsafePerformIO)
-import Unsafe.Coerce (unsafeCoerce)
-
--- minimum needed for nhc98 to pretend it has Exceptions
-
-{-
-data Exception = IOException IOException
- | ArithException ArithException
- | ArrayException ArrayException
- | AsyncException AsyncException
- | ExitException ExitCode
- deriving Show
--}
-class ({-Typeable e,-} Show e) => Exception e where
- toException :: e -> SomeException
- fromException :: SomeException -> Maybe e
-
-data SomeException = forall e . Exception e => SomeException e
-
-INSTANCE_TYPEABLE0(SomeException,someExceptionTc,"SomeException")
-
-instance Show SomeException where
- showsPrec p (SomeException e) = showsPrec p e
-instance Exception SomeException where
- toException se = se
- fromException = Just
-
-type IOException = IOError
-instance Exception IOError where
- toException = SomeException
- fromException (SomeException e) = Just (unsafeCoerce e)
-
-data ArithException
-data ArrayException
-data AsyncException
-data AssertionFailed
-data PatternMatchFail
-data NoMethodError
-data Deadlock
-data BlockedOnDeadMVar
-data BlockedIndefinitely
-data ErrorCall
-data RecConError
-data RecSelError
-data RecUpdError
-instance Show ArithException
-instance Show ArrayException
-instance Show AsyncException
-instance Show AssertionFailed
-instance Show PatternMatchFail
-instance Show NoMethodError
-instance Show Deadlock
-instance Show BlockedOnDeadMVar
-instance Show BlockedIndefinitely
-instance Show ErrorCall
-instance Show RecConError
-instance Show RecSelError
-instance Show RecUpdError
-
-catch :: Exception e
- => IO a -- ^ The computation to run
- -> (e -> IO a) -- ^ Handler to invoke if an exception is raised
- -> IO a
-catch io h = H'98.catch io (h . fromJust . fromException . toException)
-
-throwIO :: Exception e => e -> IO a
-throwIO = ioError . fromJust . fromException . toException
-
-throw :: Exception e => e -> a
-throw = unsafePerformIO . throwIO
-
-evaluate :: a -> IO a
-evaluate x = x `seq` return x
-
-assert :: Bool -> a -> a
-assert True x = x
-assert False _ = throw (toException (UserError "" "Assertion failed"))
-