Copyright | (c) 2009 - 2014 Peter Trsko |
---|---|
License | BSD3 |
Stability | provisional |
Portability | non-portable (CPP, NoImplicitPrelude, depends on non-portable module) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
- class Exception e => HiddenException e where
- hideException :: MonadThrow m => Throws e m a -> m a
- hideWith :: (Exception e, HiddenException e', MonadCatch m) => (e -> e') -> Throws e m a -> m a
- throwHidden :: (HiddenException e, MonadThrow m) => e -> m a
- throw' :: (HiddenException e, MonadThrow m) => e -> m a
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
class Exception e => HiddenException e where Source
Class for exception that can be removed from the type signature. Default
implementation for hideException
method is provided.
Nothing
hideException :: MonadThrow m => Throws e m a -> m a Source
Hide exception tag.
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.
Example:
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 hideIOException :: (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
.