tagged-exception-core- Reflect exceptions using phantom types.

Copyright(c) 2009 - 2014 Peter Trsko
Portabilitynon-portable (CPP, NoImplicitPrelude, depends on non-portable module)
Safe HaskellSafe-Inferred






HiddenException class

Since HiddenException provides default implementation for hide method making instances of it is trivial. Example of how to create instance of HiddenException:

data MyException = MyException String
  deriving (Typeable)

instance Show MyException where
    showsPrec _ (MyException msg) =
        showString "MyException: " . shows msg

instance Exception MyException
instance HiddenException MyException

Mapping existing visible exception to hidden ones

This is a prefered way of hiding exceptions. Difference from just hiding the type tag and mapping it in to hidden exception is that in later case we can provide additional information. Most important is to specify why that particluar exception was hidden.


data UnrecoverableException
    = UnrecoverableIOException String IOException
  deriving (Typeable)

instance Show UnrecoverableException where
    showsPrec _ (UnrecoverableIOException info e)
        showString "Unrecoverable exception occurred in "
        . showString info . showString ": " . shows e

instance Exception UnrecoverableException
instance HiddenException UnrecoverableException

    :: (MonadCatch e)
    => String
    -> Throws IOException m a
    -> m a
hideIOException = hideWith . UnrecoverableIOException

hideWith :: (Exception e, HiddenException e', MonadCatch m) => (e -> e') -> Throws e m a -> m a Source

Map exception before hiding it.

This is the preferred way to do exception hiding, by mapping it in to a different exception that better describes its fatality.

Raising hidden exceptions

throwHidden :: (HiddenException e, MonadThrow m) => e -> m a Source

Throw exceptions and then disregard type tag.

throw' :: (HiddenException e, MonadThrow m) => e -> m a Source

Alias for throwHidden.