| Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2019 Kowainik |
|---|---|
| License | MIT |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Relude.Exception
Description
Re-exports most useful functionality from 'safe-exceptions'. Also
provides some functions to work with exceptions over MonadError.
Synopsis
- data SomeException where
- SomeException :: forall e. Exception e => e -> SomeException
- class (Typeable e, Show e) => Exception e where
- toException :: e -> SomeException
- fromException :: SomeException -> Maybe e
- displayException :: e -> String
- data Bug = Bug SomeException CallStack
- bug :: (HasCallStack, Exception e) => e -> a
- pattern Exc :: Exception e => e -> SomeException
Documentation
data SomeException where #
Constructors
| SomeException :: forall e. Exception e => e -> SomeException |
Instances
| Show SomeException | |
Defined in GHC.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS show :: SomeException -> String showList :: [SomeException] -> ShowS | |
| Exception SomeException | |
Defined in GHC.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # | |
class (Typeable e, Show e) => Exception e where #
Minimal complete definition
Nothing
Methods
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
Instances
Type that represents exceptions used in cases when a particular codepath is not meant to be ever executed, but happens to be executed anyway.
Constructors
| Bug SomeException CallStack |
Instances
| Show Bug # | |
| Exception Bug # | |
Defined in Relude.Exception Methods toException :: Bug -> SomeException # fromException :: SomeException -> Maybe Bug # displayException :: Bug -> String # | |
bug :: (HasCallStack, Exception e) => e -> a #
Generate a pure value which, when forced, will synchronously
throw the exception wrapped into Bug data type.
pattern Exc :: Exception e => e -> SomeException #
Pattern synonym to easy pattern matching on exceptions. So intead of writing something like this:
isNonCriticalExc :: SomeException -> Bool
isNonCriticalExc e
| Just (_ :: NodeAttackedError) <- fromException e = True
| Just DialogUnexpected{} <- fromException e = True
| otherwise = False
you can use Exc pattern synonym:
isNonCriticalExc :: SomeException -> Bool
isNonCriticalExc = case
Exc (_ :: NodeAttackedError) -> True -- matching all exceptions of type NodeAttackedError
Exc DialogUnexpected{} -> True
_ -> False
This pattern is bidirectional. You can use Exc e instead of toException e.