Catch an exception. This works just like
catch, but it also
will attempt to catch
AnnotatedException e. The
annotations will be preserved in the handler, so rethrowing exceptions
will retain the context.
Let's consider a few examples, that share this import and exception
type.
import qualified Control.Exception.Safe as Safe
import Control.Exception.Annotated
data TestException deriving (Show, Exception)
We can throw an exception and catch it as usual.
throw TestException `catch` \TestException ->
putStrLn "ok!"
We can throw an exception and catch it with annotations.
throw TestException `catch` \(AnnotatedException anns TestException) ->
putStrLn "ok!"
We can throw an exception and catch it as a
AnnotatedException SomeException.
throw TestException `catch` \(AnnotatedException anns (e :: SomeException) ->
putStrLn "ok!"