uniform-error-0.1.0: Handling errors in the uniform framework
Safe HaskellNone
LanguageHaskell2010

Uniform.Error

Synopsis

Documentation

runErr :: ErrIO a -> IO (ErrOrVal a) Source #

runErr to avoid the depreceated message for runErrorT, which is identical

runErrorVoid :: ErrIO () -> IO () Source #

run an operation in ErrIO which is not returning anything simpler to use than runErr

undef :: Text -> a Source #

for type specification, not to be evaluated

bracketErrIO Source #

Arguments

:: ErrIO a

computation to run first ("acquire resource")

-> (a -> ErrIO b)

computation to run last ("release resource")

-> (a -> ErrIO c)

computation to run in-between

-> ErrIO c 

callIO :: (MonadError m, MonadIO m, ErrorType m ~ Text) => IO a -> m a Source #

this is using catch to grab all errors

errorT :: [Text] -> a Source #

a list of texts is output with failure

headNoteT :: [Text] -> [a] -> a Source #

startProg :: Show a => Text -> ErrIO a -> IO () Source #

readNote :: (Partial, Read a) => String -> String -> a #

readNote uses readEitherSafe for the error message.

headNote :: Partial => String -> [a] -> a #

class Monad m => MonadIO (m :: Type -> Type) where #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances

Instances details
MonadIO IO

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.IO.Class

Methods

liftIO :: IO a -> IO a #

MonadIO Q 
Instance details

Defined in Language.Haskell.TH.Syntax

Methods

liftIO :: IO a -> Q a #

MonadIO Snap 
Instance details

Defined in Snap.Internal.Core

Methods

liftIO :: IO a -> Snap a #

MonadIO m => MonadIO (ListT m) 
Instance details

Defined in Control.Monad.Trans.List

Methods

liftIO :: IO a -> ListT m a #

MonadIO m => MonadIO (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftIO :: IO a -> MaybeT m a #

(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

liftIO :: IO a -> WriterT w m a #

MonadIO m => MonadIO (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

liftIO :: IO a -> StateT s m a #

MonadIO m => MonadIO (ReaderT r m) 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

liftIO :: IO a -> ReaderT r m a #

(Error e, MonadIO m) => MonadIO (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftIO :: IO a -> ErrorT e m a #

MonadIO m => MonadIO (IdentityT m) 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

liftIO :: IO a -> IdentityT m a #

MonadIO m => MonadIO (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

liftIO :: IO a -> StateT s m a #

(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

liftIO :: IO a -> WriterT w m a #

(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

liftIO :: IO a -> RWST r w s m a #

(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

liftIO :: IO a -> RWST r w s m a #

unless :: Applicative f => Bool -> f () -> f () #

The reverse of when.

when :: Applicative f => Bool -> f () -> f () #

Conditional execution of Applicative expressions. For example,

when debug (putStrLn "Debugging")

will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.

class Error a #

An exception to be thrown.

Minimal complete definition: noMsg or strMsg.

Instances

Instances details
Error Text Source # 
Instance details

Defined in Uniform.Error

Methods

noMsg :: Text #

strMsg :: String -> Text #

Error IOException 
Instance details

Defined in Control.Monad.Trans.Error

ErrorList a => Error [a]

A string can be thrown as an error.

Instance details

Defined in Control.Monad.Trans.Error

Methods

noMsg :: [a] #

strMsg :: String -> [a] #

data ErrorT e (m :: Type -> Type) a #

The error monad transformer. It can be used to add error handling to other monads.

The ErrorT Monad structure is parameterized over two things:

  • e - The error type.
  • m - The inner monad.

The return function yields a successful computation, while >>= sequences two subcomputations, failing on the first error.

Instances

Instances details
(Error e, MonadBaseControl b m) => MonadBaseControl b (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Control

Associated Types

type StM (ErrorT e m) a #

Methods

liftBaseWith :: (RunInBase (ErrorT e m) b -> b a) -> ErrorT e m a #

restoreM :: StM (ErrorT e m) a -> ErrorT e m a #

MonadTrans (ErrorT e) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

lift :: Monad m => m a -> ErrorT e m a #

Error e => MonadTransControl (ErrorT e) 
Instance details

Defined in Control.Monad.Trans.Control

Associated Types

type StT (ErrorT e) a #

Methods

liftWith :: Monad m => (Run (ErrorT e) -> m a) -> ErrorT e m a #

restoreT :: Monad m => m (StT (ErrorT e) a) -> ErrorT e m a #

(Monad m, Error e) => Monad (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

(>>=) :: ErrorT e m a -> (a -> ErrorT e m b) -> ErrorT e m b #

(>>) :: ErrorT e m a -> ErrorT e m b -> ErrorT e m b #

return :: a -> ErrorT e m a #

Functor m => Functor (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

fmap :: (a -> b) -> ErrorT e m a -> ErrorT e m b #

(<$) :: a -> ErrorT e m b -> ErrorT e m a #

(MonadFix m, Error e) => MonadFix (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

mfix :: (a -> ErrorT e m a) -> ErrorT e m a #

(Monad m, Error e) => MonadFail (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

fail :: String -> ErrorT e m a #

(Functor m, Monad m) => Applicative (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

pure :: a -> ErrorT e m a #

(<*>) :: ErrorT e m (a -> b) -> ErrorT e m a -> ErrorT e m b #

liftA2 :: (a -> b -> c) -> ErrorT e m a -> ErrorT e m b -> ErrorT e m c #

(*>) :: ErrorT e m a -> ErrorT e m b -> ErrorT e m b #

(<*) :: ErrorT e m a -> ErrorT e m b -> ErrorT e m a #

Foldable f => Foldable (ErrorT e f) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

fold :: Monoid m => ErrorT e f m -> m #

foldMap :: Monoid m => (a -> m) -> ErrorT e f a -> m #

foldMap' :: Monoid m => (a -> m) -> ErrorT e f a -> m #

foldr :: (a -> b -> b) -> b -> ErrorT e f a -> b #

foldr' :: (a -> b -> b) -> b -> ErrorT e f a -> b #

foldl :: (b -> a -> b) -> b -> ErrorT e f a -> b #

foldl' :: (b -> a -> b) -> b -> ErrorT e f a -> b #

foldr1 :: (a -> a -> a) -> ErrorT e f a -> a #

foldl1 :: (a -> a -> a) -> ErrorT e f a -> a #

toList :: ErrorT e f a -> [a] #

null :: ErrorT e f a -> Bool #

length :: ErrorT e f a -> Int #

elem :: Eq a => a -> ErrorT e f a -> Bool #

maximum :: Ord a => ErrorT e f a -> a #

minimum :: Ord a => ErrorT e f a -> a #

sum :: Num a => ErrorT e f a -> a #

product :: Num a => ErrorT e f a -> a #

Traversable f => Traversable (ErrorT e f) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

traverse :: Applicative f0 => (a -> f0 b) -> ErrorT e f a -> f0 (ErrorT e f b) #

sequenceA :: Applicative f0 => ErrorT e f (f0 a) -> f0 (ErrorT e f a) #

mapM :: Monad m => (a -> m b) -> ErrorT e f a -> m (ErrorT e f b) #

sequence :: Monad m => ErrorT e f (m a) -> m (ErrorT e f a) #

(Functor m, Monad m, Error e) => Alternative (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

empty :: ErrorT e m a #

(<|>) :: ErrorT e m a -> ErrorT e m a -> ErrorT e m a #

some :: ErrorT e m a -> ErrorT e m [a] #

many :: ErrorT e m a -> ErrorT e m [a] #

(Monad m, Error e) => MonadPlus (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

mzero :: ErrorT e m a #

mplus :: ErrorT e m a -> ErrorT e m a -> ErrorT e m a #

Contravariant m => Contravariant (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

contramap :: (a -> b) -> ErrorT e m b -> ErrorT e m a #

(>$) :: b -> ErrorT e m b -> ErrorT e m a #

(Eq e, Eq1 m) => Eq1 (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftEq :: (a -> b -> Bool) -> ErrorT e m a -> ErrorT e m b -> Bool #

(Ord e, Ord1 m) => Ord1 (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftCompare :: (a -> b -> Ordering) -> ErrorT e m a -> ErrorT e m b -> Ordering #

(Read e, Read1 m) => Read1 (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (ErrorT e m a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [ErrorT e m a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (ErrorT e m a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [ErrorT e m a] #

(Show e, Show1 m) => Show1 (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ErrorT e m a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [ErrorT e m a] -> ShowS #

(Error e, MonadIO m) => MonadIO (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftIO :: IO a -> ErrorT e m a #

(Monad m, Error e) => MonadError (ErrorT e m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (ErrorT e m) #

Methods

throwError :: ErrorType (ErrorT e m) -> ErrorT e m a #

catchError :: ErrorT e m a -> (ErrorType (ErrorT e m) -> ErrorT e m a) -> ErrorT e m a #

(Error e, MonadState m) => MonadState (ErrorT e m) 
Instance details

Defined in Control.Monad.State.Class

Associated Types

type StateType (ErrorT e m) #

Methods

get :: ErrorT e m (StateType (ErrorT e m)) #

put :: StateType (ErrorT e m) -> ErrorT e m () #

(Error e, PrimMonad m) => PrimMonad (ErrorT e m) 
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState (ErrorT e m) #

Methods

primitive :: (State# (PrimState (ErrorT e m)) -> (# State# (PrimState (ErrorT e m)), a #)) -> ErrorT e m a #

(Eq e, Eq1 m, Eq a) => Eq (ErrorT e m a) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

(==) :: ErrorT e m a -> ErrorT e m a -> Bool #

(/=) :: ErrorT e m a -> ErrorT e m a -> Bool #

(Ord e, Ord1 m, Ord a) => Ord (ErrorT e m a) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

compare :: ErrorT e m a -> ErrorT e m a -> Ordering #

(<) :: ErrorT e m a -> ErrorT e m a -> Bool #

(<=) :: ErrorT e m a -> ErrorT e m a -> Bool #

(>) :: ErrorT e m a -> ErrorT e m a -> Bool #

(>=) :: ErrorT e m a -> ErrorT e m a -> Bool #

max :: ErrorT e m a -> ErrorT e m a -> ErrorT e m a #

min :: ErrorT e m a -> ErrorT e m a -> ErrorT e m a #

(Read e, Read1 m, Read a) => Read (ErrorT e m a) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

readsPrec :: Int -> ReadS (ErrorT e m a) #

readList :: ReadS [ErrorT e m a] #

readPrec :: ReadPrec (ErrorT e m a) #

readListPrec :: ReadPrec [ErrorT e m a] #

(Show e, Show1 m, Show a) => Show (ErrorT e m a) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

showsPrec :: Int -> ErrorT e m a -> ShowS #

show :: ErrorT e m a -> String #

showList :: [ErrorT e m a] -> ShowS #

type StT (ErrorT e) a 
Instance details

Defined in Control.Monad.Trans.Control

type StT (ErrorT e) a = Either e a
type ErrorType (ErrorT e m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (ErrorT e m) = e
type StateType (ErrorT e m) 
Instance details

Defined in Control.Monad.State.Class

type StateType (ErrorT e m) = StateType m
type PrimState (ErrorT e m) 
Instance details

Defined in Control.Monad.Primitive

type PrimState (ErrorT e m) = PrimState m
type StM (ErrorT e m) a 
Instance details

Defined in Control.Monad.Trans.Control

type StM (ErrorT e m) a = ComposeSt (ErrorT e) m a

type family ErrorType (m :: Type -> Type) #

Instances

Instances details
type ErrorType IO 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (Either e) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (Either e) = e
type ErrorType (ListT m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (MaybeT m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (WriterT w m) = ErrorType m
type ErrorType (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (StateT s m) = ErrorType m
type ErrorType (ReaderT r m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (ReaderT r m) = ErrorType m
type ErrorType (ErrorT e m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (ErrorT e m) = e
type ErrorType (IdentityT m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (StateT s m) = ErrorType m
type ErrorType (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (WriterT w m) = ErrorType m
type ErrorType (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (RWST r w s m) = ErrorType m
type ErrorType (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

type ErrorType (RWST r w s m) = ErrorType m

class Monad m => MonadError (m :: Type -> Type) where #

The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.

Is parameterized over the type of error information and the monad type constructor. It is common to use Either String as the monad type constructor for an error monad in which error descriptions take the form of strings. In that case and many other common cases the resulting monad is already defined as an instance of the MonadError class. You can also define your own error type and/or use a monad type constructor other than Either String or Either IOError. In these cases you will have to explicitly define instances of the Error and/or MonadError classes.

Associated Types

type ErrorType (m :: Type -> Type) #

Methods

throwError :: ErrorType m -> m a #

Is used within a monadic computation to begin exception processing.

catchError :: m a -> (ErrorType m -> m a) -> m a #

A handler function to handle previous errors and return to normal execution. A common idiom is:

do { action1; action2; action3 } `catchError` handler

where the action functions can call throwError. Note that handler and the do-block must have the same return type.

Instances

Instances details
MonadError IO 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType IO #

Methods

throwError :: ErrorType IO -> IO a #

catchError :: IO a -> (ErrorType IO -> IO a) -> IO a #

Error e => MonadError (Either e) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (Either e) #

Methods

throwError :: ErrorType (Either e) -> Either e a #

catchError :: Either e a -> (ErrorType (Either e) -> Either e a) -> Either e a #

MonadError m => MonadError (ListT m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (ListT m) #

Methods

throwError :: ErrorType (ListT m) -> ListT m a #

catchError :: ListT m a -> (ErrorType (ListT m) -> ListT m a) -> ListT m a #

MonadError m => MonadError (MaybeT m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (MaybeT m) #

Methods

throwError :: ErrorType (MaybeT m) -> MaybeT m a #

catchError :: MaybeT m a -> (ErrorType (MaybeT m) -> MaybeT m a) -> MaybeT m a #

(Monoid w, MonadError m) => MonadError (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (WriterT w m) #

Methods

throwError :: ErrorType (WriterT w m) -> WriterT w m a #

catchError :: WriterT w m a -> (ErrorType (WriterT w m) -> WriterT w m a) -> WriterT w m a #

MonadError m => MonadError (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (StateT s m) #

Methods

throwError :: ErrorType (StateT s m) -> StateT s m a #

catchError :: StateT s m a -> (ErrorType (StateT s m) -> StateT s m a) -> StateT s m a #

MonadError m => MonadError (ReaderT r m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (ReaderT r m) #

Methods

throwError :: ErrorType (ReaderT r m) -> ReaderT r m a #

catchError :: ReaderT r m a -> (ErrorType (ReaderT r m) -> ReaderT r m a) -> ReaderT r m a #

(Monad m, Error e) => MonadError (ErrorT e m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (ErrorT e m) #

Methods

throwError :: ErrorType (ErrorT e m) -> ErrorT e m a #

catchError :: ErrorT e m a -> (ErrorType (ErrorT e m) -> ErrorT e m a) -> ErrorT e m a #

MonadError m => MonadError (IdentityT m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (IdentityT m) #

MonadError m => MonadError (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (StateT s m) #

Methods

throwError :: ErrorType (StateT s m) -> StateT s m a #

catchError :: StateT s m a -> (ErrorType (StateT s m) -> StateT s m a) -> StateT s m a #

(Monoid w, MonadError m) => MonadError (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (WriterT w m) #

Methods

throwError :: ErrorType (WriterT w m) -> WriterT w m a #

catchError :: WriterT w m a -> (ErrorType (WriterT w m) -> WriterT w m a) -> WriterT w m a #

(Monoid w, MonadError m) => MonadError (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (RWST r w s m) #

Methods

throwError :: ErrorType (RWST r w s m) -> RWST r w s m a #

catchError :: RWST r w s m a -> (ErrorType (RWST r w s m) -> RWST r w s m a) -> RWST r w s m a #

(Monoid w, MonadError m) => MonadError (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

Associated Types

type ErrorType (RWST r w s m) #

Methods

throwError :: ErrorType (RWST r w s m) -> RWST r w s m a #

catchError :: RWST r w s m a -> (ErrorType (RWST r w s m) -> RWST r w s m a) -> RWST r w s m a #

bracket #

Arguments

:: IO a

computation to run first ("acquire resource")

-> (a -> IO b)

computation to run last ("release resource")

-> (a -> IO c)

computation to run in-between

-> IO c 

When you want to acquire a resource, do some work with it, and then release the resource, it is a good idea to use bracket, because bracket will install the necessary exception handler to release the resource in the event that an exception is raised during the computation. If an exception is raised, then bracket will re-raise the exception (after performing the release).

A common example is opening a file:

bracket
  (openFile "filename" ReadMode)
  (hClose)
  (\fileHandle -> do { ... })

The arguments to bracket are in this order so that we can partially apply it, e.g.:

withFile name mode = bracket (openFile name mode) hClose

catch #

Arguments

:: Exception e 
=> IO a

The computation to run

-> (e -> IO a)

Handler to invoke if an exception is raised

-> IO a 

This is the simplest of the exception-catching functions. It takes a single argument, runs it, and if an exception is raised the "handler" is executed, with the value of the exception passed as an argument. Otherwise, the result is returned as normal. For example:

  catch (readFile f)
        (\e -> do let err = show (e :: IOException)
                  hPutStr stderr ("Warning: Couldn't open " ++ f ++ ": " ++ err)
                  return "")

Note that we have to give a type signature to e, or the program will not typecheck as the type is ambiguous. While it is possible to catch exceptions of any type, see the section "Catching all exceptions" (in Control.Exception) for an explanation of the problems with doing so.

For catching exceptions in pure (non-IO) expressions, see the function evaluate.

Note that due to Haskell's unspecified evaluation order, an expression may throw one of several possible exceptions: consider the expression (error "urk") + (1 `div` 0). Does the expression throw ErrorCall "urk", or DivideByZero?

The answer is "it might throw either"; the choice is non-deterministic. If you are catching any type of exception then you might catch either. If you are calling catch with type IO Int -> (ArithException -> IO Int) -> IO Int then the handler may get run with DivideByZero as an argument, or an ErrorCall "urk" exception may be propogated further up. If you call it again, you might get a the opposite behaviour. This is ok, because catch is an IO computation.

class (Typeable e, Show e) => Exception e #

Any type that you wish to throw or catch as an exception must be an instance of the Exception class. The simplest case is a new exception type directly below the root:

data MyException = ThisException | ThatException
    deriving Show

instance Exception MyException

The default method definitions in the Exception class do what we need in this case. You can now throw and catch ThisException and ThatException as exceptions:

*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
Caught ThisException

In more complicated examples, you may wish to define a whole hierarchy of exceptions:

---------------------------------------------------------------------
-- Make the root exception type for all the exceptions in a compiler

data SomeCompilerException = forall e . Exception e => SomeCompilerException e

instance Show SomeCompilerException where
    show (SomeCompilerException e) = show e

instance Exception SomeCompilerException

compilerExceptionToException :: Exception e => e -> SomeException
compilerExceptionToException = toException . SomeCompilerException

compilerExceptionFromException :: Exception e => SomeException -> Maybe e
compilerExceptionFromException x = do
    SomeCompilerException a <- fromException x
    cast a

---------------------------------------------------------------------
-- Make a subhierarchy for exceptions in the frontend of the compiler

data SomeFrontendException = forall e . Exception e => SomeFrontendException e

instance Show SomeFrontendException where
    show (SomeFrontendException e) = show e

instance Exception SomeFrontendException where
    toException = compilerExceptionToException
    fromException = compilerExceptionFromException

frontendExceptionToException :: Exception e => e -> SomeException
frontendExceptionToException = toException . SomeFrontendException

frontendExceptionFromException :: Exception e => SomeException -> Maybe e
frontendExceptionFromException x = do
    SomeFrontendException a <- fromException x
    cast a

---------------------------------------------------------------------
-- Make an exception type for a particular frontend compiler exception

data MismatchedParentheses = MismatchedParentheses
    deriving Show

instance Exception MismatchedParentheses where
    toException   = frontendExceptionToException
    fromException = frontendExceptionFromException

We can now catch a MismatchedParentheses exception as MismatchedParentheses, SomeFrontendException or SomeCompilerException, but not other types, e.g. IOException:

*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
*** Exception: MismatchedParentheses

Instances

Instances details
Exception Void

Since: base-4.8.0.0

Instance details

Defined in Data.Void

Exception PatternMatchFail

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception RecSelError

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception RecConError

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception RecUpdError

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception NoMethodError

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception TypeError

Since: base-4.9.0.0

Instance details

Defined in Control.Exception.Base

Exception NonTermination

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception NestedAtomically

Since: base-4.0

Instance details

Defined in Control.Exception.Base

Exception BlockedIndefinitelyOnMVar

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception BlockedIndefinitelyOnSTM

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception Deadlock

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception AllocationLimitExceeded

Since: base-4.8.0.0

Instance details

Defined in GHC.IO.Exception

Exception CompactionFailed

Since: base-4.10.0.0

Instance details

Defined in GHC.IO.Exception

Exception AssertionFailed

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception SomeAsyncException

Since: base-4.7.0.0

Instance details

Defined in GHC.IO.Exception

Exception AsyncException

Since: base-4.7.0.0

Instance details

Defined in GHC.IO.Exception

Exception ArrayException

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception FixIOException

Since: base-4.11.0.0

Instance details

Defined in GHC.IO.Exception

Exception ExitCode

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception IOException

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Exception ArithException

Since: base-4.0.0.0

Instance details

Defined in GHC.Exception.Type

Exception SomeException

Since: base-3.0

Instance details

Defined in GHC.Exception.Type

Exception EscapeSnap 
Instance details

Defined in Snap.Internal.Core

Exception NoHandlerException 
Instance details

Defined in Snap.Internal.Core

Exception [Text] Source # 
Instance details

Defined in Uniform.Error

data SomeException #

The SomeException type is the root of the exception type hierarchy. When an exception of type e is thrown, behind the scenes it is encapsulated in a SomeException.

Instances

Instances details
Show SomeException

Since: base-3.0

Instance details

Defined in GHC.Exception.Type

Exception SomeException

Since: base-3.0

Instance details

Defined in GHC.Exception.Type

Orphan instances

Error Text Source # 
Instance details

Methods

noMsg :: Text #

strMsg :: String -> Text #

CharChains2 IOError Text Source # 
Instance details

Methods

show' :: IOError -> Text #

Exception [Text] Source # 
Instance details