Module

Control.Monad.Except.Checked

Package
purescript-checked-exceptions
Repository
natefaubion/purescript-checked-exceptions

Extensible checked exceptions with polymorphic variants

This module provides helpers for using Variant with ExceptT. When combined, we get a mechanism for extensible, checked exceptions. That is, exceptions can be defined and used anywhere, and handled as needed. Handling an exception eliminates it from the type, giving us proof that it no longer occurs.

#ExceptV Source

type ExceptV :: Row Type -> (Type -> Type) -> Type -> Typetype ExceptV exc = ExceptT (Variant exc)

#handleError Source

handleError :: forall m handlers excHandled excIn excOut rl a. RowToList handlers rl => VariantMatchCases rl excHandled (ExceptV excOut m a) => Union excHandled excOut excIn => Monad m => Record handlers -> ExceptV excIn m a -> ExceptV excOut m a

Catches and eliminates exceptions given a record of handlers. Unhandled exceptions are re-propragated. Record fields map to the label for the exception being handled.

An example for handling HTTP exceptions might be:

request # handleError
  { httpNotFound: \_ -> ...
  , httpServerError: \error -> ...
  }

#handleErrors Source

handleErrors :: forall m handlers excHandled excIn rl a. RowToList handlers rl => VariantMatchCases rl excHandled (m a) => Union excHandled () excIn => Monad m => Record handlers -> ExceptV excIn m a -> m a

Similar to handleError, except it handles all errors. Has the benefit that you can execute error handlers in the parent monad m.

#safe Source

safe :: forall m a. Functor m => ExceptV () m a -> m a

Safely removes the ExceptT layer when all exceptions have been handled.