| Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 Kowainik |
|---|---|
| License | MIT |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Stability | Stable |
| Portability | Portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Relude.Exception
Contents
- Control.Exception reexports
Bugs
Description
Re-exports most useful functionality from the Control.Exception module. Also provides some convenient utilities to throw and handle exceptions.
Synopsis
- class (Typeable e, Show e) => Exception e where
- toException :: e -> SomeException
- fromException :: SomeException -> Maybe e
- displayException :: e -> String
- backtraceDesired :: e -> Bool
- data SomeException = (Exception e, HasExceptionContext) => SomeException e
- data Bug = Bug SomeException CallStack
- bug :: (HasCallStack, Exception e) => e -> a
- pattern Exc :: Exception e => e -> SomeException
Control.Exception reexports
class (Typeable e, Show e) => Exception e where #
Minimal complete definition
Nothing
Methods
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
backtraceDesired :: e -> Bool #
Instances
data SomeException #
Constructors
| (Exception e, HasExceptionContext) => SomeException e |
Instances
| Exception SomeException | |
Defined in GHC.Internal.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # backtraceDesired :: SomeException -> Bool # | |
| Show SomeException | |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS show :: SomeException -> String showList :: [SomeException] -> ShowS | |
Bugs
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
| Exception Bug Source # | |
Defined in Relude.Exception Methods toException :: Bug -> SomeException # fromException :: SomeException -> Maybe Bug # displayException :: Bug -> String # backtraceDesired :: Bug -> Bool # | |
| Show Bug Source # | |
bug :: (HasCallStack, Exception e) => e -> a Source #
Generate a pure value which, when forced, will synchronously
throw the exception wrapped into Bug data type.
pattern Exc :: Exception e => e -> SomeException Source #
Pattern synonym to easy pattern matching on exceptions. So instead 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.