The Exception library provides an interface for raising and catching both built-in and user defined exceptions. Exceptions are defined by the following (non-abstract) datatype: data Exception = IOException IOError -- IO exceptions (from 'fail') | ArithException ArithError -- Arithmetic exceptions | ErrorCall String -- Calls to 'error' | NoMethodError String -- A non-existent method was invoked | PatternMatchFail String -- A pattern match failed | NonExhaustiveGuards String -- A guard match failed | RecSelError String -- Selecting a non-existent field | RecConError String -- Field missing in record construction | RecUpdError String -- Record doesn't contain updated field | AssertionFailed String -- Assertions | DynException Dynamic -- Dynamic exceptions | ExternalException ExtError -- External exceptions instance Eq Exception instance Ord Exception instance Show Exception data ArithError = Overflow | Underflow | LossOfPrecision | DivideByZero | Denormal instance Eq ArithError instance Ord ArithError instance Show ArithError data ExtError = StackOverflow | HeapOverflow | ThreadKilled instance Eq ExtError instance Ord ExtError instance Show ExtError An implementation should raise the appropriate exception when one of the above conditions arises. Note: GHC currently doesn't generate the arithmetic or the external exceptions. Exceptions may be thrown explicitly from anywhere: throw :: Exception -> a Exceptions may be caught and examined in the catch :: IO a -> (Exception -> IO a) -> IO a catchIO :: IO a -> (IOError -> IO a) -> IO a catchArith :: IO a -> (ArithError -> IO a) -> IO a catchError :: IO a -> (String -> IO a) -> IO a getException :: a -> IO (Maybe Exception) getExceptionIO :: IO a -> IO (Either Exception a) Each of the functions

Because the ), which allows exception values of any type in the throwDyn :: Typeable exception => exception -> b catchDyn :: Typeable exception => IO a -> (exception -> IO a) -> IO a The