File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 11# effectful-core-2.6.0.0 (????-??-??)
22* Adjust ` generalBracket ` with ` base >= 4.21 ` to make use of the new exception
33 annotation mechanism.
4+ * Add ` withException ` to ` Effectful.Exception ` .
45* ** Breaking changes** :
56 - Change the order of type parameters in ` raise ` for better usability.
67 - ` Effectful.Error.Static.ErrorWrapper ` is no longer caught by ` catchSync ` .
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ module Effectful.Exception
5959 , C. ExitCase (.. )
6060 , finally
6161 , onException
62+ , withException
6263
6364 -- * Utils
6465
@@ -512,6 +513,27 @@ onException
512513onException action handler = reallyUnsafeUnliftIO $ \ unlift -> do
513514 E. onException (unlift action) (unlift handler)
514515
516+ -- | A variant of 'onException' that gives access to the exception.
517+ --
518+ -- @since 2.6.0.0
519+ withException
520+ :: E. Exception e
521+ => Eff es a
522+ -> (e -> Eff es b )
523+ -- ^ Computation to run last when an exception or
524+ -- t'Effectful.Error.Static.Error' was thrown.
525+ -> Eff es a
526+ withException action cleanup = do
527+ #if MIN_VERSION_base(4,21,0)
528+ action `catchNoPropagate` \ ec@ (E. ExceptionWithContext _ e) -> do
529+ _ <- annotateIO (E. WhileHandling (E. toException ec)) (cleanup e)
530+ rethrowIO ec
531+ #else
532+ action `catch` \ e -> do
533+ _ <- cleanup e
534+ throwIO e
535+ #endif
536+
515537----------------------------------------
516538-- Utils
517539
Original file line number Diff line number Diff line change 11# effectful-core-2.6.0.0 (????-??-??)
22* Adjust ` generalBracket ` with ` base >= 4.21 ` to make use of the new exception
33 annotation mechanism.
4+ * Add ` withException ` to ` Effectful.Exception ` .
45* Re-export ` ThreadId ` from ` Effectful.Concurrent ` for convenience.
56* ** Breaking changes** :
67 - Change the order of type parameters in ` raise ` for better usability.
You can’t perform that action at this time.
0 commit comments