module Try.Exceptions.Theory where
Exceptions
- Safe exception handling
- Types of exceptions:
synchronous
- generated inIO
, thrown inside a single thread. Allowrecovery
andcleanup
asynchronous
- generated from outside a thread. Allowcleanup
, butno recovery
impure
- generated in a pure code, thrown when a thunk gets evaluated.- Example:
error
- Example:
- Types of exceptions:
- [Exceptions and concurrency] - YT
- use [safe-exceptions]
From Haskell in Depth (Chapter 7)
- Avoid using exceptions when possible
- Due to laziness, an exception in an expression doesn't happen until that expression gets evaluated.
- A thread can be killed by other threads or the runtime system (due to memory exhaustion, etc.)
- Types of exceptions:
programmable
- used in pure monad stacks (e.g.,
ExceptT
)
- used in pure monad stacks (e.g.,
extensible
- Extensions thrown anywhere, caught only in
IO
- Supported by the GHC runtime system
imprecise
exceptions - thrown in pure code, order unspecified by the runtime system- All exceptions have an instance of
Exception
and are values of theSomeException
type
- Extensions thrown anywhere, caught only in
- packages -
exceptions
,safe-exceptions