2 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
3 {-# OPTIONS_HADDOCK hide #-}
4 -----------------------------------------------------------------------------
6 -- Module : GHC.Exception
7 -- Copyright : (c) The University of Glasgow, 1998-2002
8 -- License : see libraries/base/LICENSE
10 -- Maintainer : cvs-ghc@haskell.org
11 -- Stability : internal
12 -- Portability : non-portable (GHC extensions)
14 -- Exceptions and exception-handling functions.
16 -----------------------------------------------------------------------------
19 module GHC.Exception where
22 import {-# SOURCE #-} Data.Typeable
27 %*********************************************************
29 \subsection{Exceptions}
31 %*********************************************************
34 data SomeException = forall e . Exception e => SomeException e
37 instance Show SomeException where
38 showsPrec p (SomeException e) = showsPrec p e
40 class (Typeable e, Show e) => Exception e where
41 toException :: e -> SomeException
42 fromException :: SomeException -> Maybe e
44 toException = SomeException
45 fromException (SomeException e) = cast e
47 instance Exception SomeException where
52 %*********************************************************
54 \subsection{Primitive throw}
56 %*********************************************************
59 -- | Throw an exception. Exceptions may be thrown from purely
60 -- functional code, but may only be caught within the 'IO' monad.
61 throw :: Exception e => e -> a
62 throw e = raise# (toException e)
66 data ErrorCall = ErrorCall String
69 instance Exception ErrorCall
71 instance Show ErrorCall where
72 showsPrec _ (ErrorCall err) = showString err
76 -- |The type of arithmetic exceptions
83 deriving (Eq, Ord, Typeable)
85 instance Exception ArithException
87 instance Show ArithException where
88 showsPrec _ Overflow = showString "arithmetic overflow"
89 showsPrec _ Underflow = showString "arithmetic underflow"
90 showsPrec _ LossOfPrecision = showString "loss of precision"
91 showsPrec _ DivideByZero = showString "divide by zero"
92 showsPrec _ Denormal = showString "denormal"