Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions effectful-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# effectful-core-2.6.0.0 (????-??-??)
* Adjust `generalBracket` with `base >= 4.21` to make use of the new exception
annotation mechanism.
* Add `withException` to `Effectful.Exception`.
* **Breaking changes**:
- Change the order of type parameters in `raise` for better usability.
- `Effectful.Error.Static.ErrorWrapper` is no longer caught by `catchSync`.
Expand Down
22 changes: 22 additions & 0 deletions effectful-core/src/Effectful/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module Effectful.Exception
, C.ExitCase(..)
, finally
, onException
, withException

-- * Utils

Expand Down Expand Up @@ -512,6 +513,27 @@ onException
onException action handler = reallyUnsafeUnliftIO $ \unlift -> do
E.onException (unlift action) (unlift handler)

-- | A variant of 'onException' that gives access to the exception.
--
-- @since 2.6.0.0
withException
:: E.Exception e
=> Eff es a
-> (e -> Eff es b)
-- ^ Computation to run last when an exception or
-- t'Effectful.Error.Static.Error' was thrown.
-> Eff es a
withException action cleanup = do
#if MIN_VERSION_base(4,21,0)
action `catchNoPropagate` \ec@(E.ExceptionWithContext _ e) -> do
_ <- annotateIO (E.WhileHandling (E.toException ec)) (cleanup e)
rethrowIO ec
#else
action `catch` \e -> do
_ <- cleanup e
throwIO e
#endif

----------------------------------------
-- Utils

Expand Down
1 change: 1 addition & 0 deletions effectful/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# effectful-core-2.6.0.0 (????-??-??)
* Adjust `generalBracket` with `base >= 4.21` to make use of the new exception
annotation mechanism.
* Add `withException` to `Effectful.Exception`.
* Re-export `ThreadId` from `Effectful.Concurrent` for convenience.
* **Breaking changes**:
- Change the order of type parameters in `raise` for better usability.
Expand Down
Loading