A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/src/GHC-Exception.html below:

GHC/Exception.lhs

\begin{code}



















module GHC.Exception where

import Data.Maybe
import  Data.Typeable (Typeable, cast)
   
import GHC.Base
import GHC.Show
\end{code} %********************************************************* %* * \subsection{Exceptions} %* * %********************************************************* \begin{code}

data SomeException = forall e . Exception e => SomeException e
    deriving Typeable

instance Show SomeException where
    showsPrec p (SomeException e) = showsPrec p e


class (Typeable e, Show e) => Exception e where
    toException   :: e -> SomeException
    fromException :: SomeException -> Maybe e

    toException = SomeException
    fromException (SomeException e) = cast e

instance Exception SomeException where
    toException se = se
    fromException = Just
\end{code} %********************************************************* %* * \subsection{Primitive throw} %* * %********************************************************* \begin{code}


throw :: Exception e => e -> a
throw e = raise# (toException e)
\end{code} \begin{code}


data ErrorCall = ErrorCall String
    deriving Typeable

instance Exception ErrorCall

instance Show ErrorCall where
    showsPrec _ (ErrorCall err) = showString err




data ArithException
  = Overflow
  | Underflow
  | LossOfPrecision
  | DivideByZero
  | Denormal
  deriving (Eq, Ord, Typeable)

instance Exception ArithException

instance Show ArithException where
  showsPrec _ Overflow        = showString "arithmetic overflow"
  showsPrec _ Underflow       = showString "arithmetic underflow"
  showsPrec _ LossOfPrecision = showString "loss of precision"
  showsPrec _ DivideByZero    = showString "divide by zero"
  showsPrec _ Denormal        = showString "denormal"

\end{code}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4