Both exceptions and Control.Exception provide a Handler type.
This lets us write combinators to build handlers that are agnostic about the choice of which of these they use.
Methods
handler :: Typeable a => Getting (First a) e a -> (a -> m r) -> h rThis builds a Handler for just the targets of a given Prism (or any Getter, really).
catches ... [ handler _AssertionFailed (s -> print $ "Assertion Failed\n" ++ s) , handler _ErrorCall (s -> print $ "Error\n" ++ s) ]This works ith both the Handler type provided by
Control.Exception:handler :: Getter SomeException a -> (a -> IO r) -> Handler r handler :: Fold SomeException a -> (a -> IO r) -> Handler r handler ::Control.Lens.Prism.Prism'SomeException a -> (a -> IO r) -> Handler r handler ::Control.Lens.Lens.Lens'SomeException a -> (a -> IO r) -> Handler r handler ::Control.Lens.Traversal.Traversal'SomeException a -> (a -> IO r) -> Handler rand with the Handler type provided by
Control.Monad.Catch:handler :: Getter SomeException a -> (a -> m r) -> Handler m r handler :: Fold SomeException a -> (a -> m r) -> Handler m r handler ::Control.Lens.Prism.Prism'SomeException a -> (a -> m r) -> Handler m r handler ::Control.Lens.Lens.Lens'SomeException a -> (a -> m r) -> Handler m r handler ::Control.Lens.Traversal.Traversal'SomeException a -> (a -> m r) -> Handler m rand with the Handler type provided by
Control.Monad.Error.Lens:handler :: Getter e a -> (a -> m r) -> Handler e m r handler :: Fold e a -> (a -> m r) -> Handler e m r handler ::Control.Lens.Prism.Prism'e a -> (a -> m r) -> Handler e m r handler ::Control.Lens.Lens.Lens'e a -> (a -> m r) -> Handler e m r handler ::Control.Lens.Traversal.Traversal'e a -> (a -> m r) -> Handler e m rhandler_ :: Typeable a => Getting (First a) e a -> m r -> h rThis builds a Handler for just the targets of a given
Control.Lens.Prism.Prism(or any Getter, really). that ignores its input and just recovers with the stated monadic action.catches ... [ handler_ _NonTermination (return "looped") , handler_ _StackOverflow (return "overflow") ]This works with the Handler type provided by
Control.Exception:handler_ :: Getter SomeException a -> IO r -> Handler r handler_ :: Fold SomeException a -> IO r -> Handler r handler_ ::Control.Lens.Prism.Prism'SomeException a -> IO r -> Handler r handler_ ::Control.Lens.Lens.Lens'SomeException a -> IO r -> Handler r handler_ ::Control.Lens.Traversal.Traversal'SomeException a -> IO r -> Handler rand with the Handler type provided by
Control.Monad.Catch:handler_ :: Getter SomeException a -> m r -> Handler m r handler_ :: Fold SomeException a -> m r -> Handler m r handler_ ::Control.Lens.Prism.Prism'SomeException a -> m r -> Handler m r handler_ ::Control.Lens.Lens.Lens'SomeException a -> m r -> Handler m r handler_ ::Control.Lens.Traversal.Traversal'SomeException a -> m r -> Handler m rand with the Handler type provided by
Control.Monad.Error.Lens:handler_ :: Getter e a -> m r -> Handler e m r handler_ :: Fold e a -> m r -> Handler e m r handler_ ::Control.Lens.Prism.Prism'e a -> m r -> Handler e m r handler_ ::Control.Lens.Lens.Lens'e a -> m r -> Handler e m r handler_ ::Control.Lens.Traversal.Traversal'e a -> m r -> Handler e m r
Instances3Handleable
Handleable SomeException IO HandlerDefined in lens-5.3.5 · Control.Lens.Internal.ExceptionTypeable m => Handleable SomeException m (Handler m)Defined in lens-5.3.5 · Control.Lens.Internal.ExceptionHandleable e m (Handler e m)Defined in lens-5.3.5 · Control.Monad.Error.Lens