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)