blob: 92ff2d8c86ce493e68446bf6db6482ade2b7085e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
module FinalizerExceptionHandler
( setFinalizerExceptionHandler
, getFinalizerExceptionHandler
, printToStderrFinalizerExceptionHandler )
where
import GHC.Exception ( SomeException(..), displayException )
import GHC.IO ( catchException )
import GHC.IO.Handle ( hPutStr )
import GHC.IO.StdHandles ( stderr )
import GHC.Weak.Finalize ( setFinalizerExceptionHandler, getFinalizerExceptionHandler )
-- | An exception handler for Handle finalization that prints the error to
-- stderr, but doesn't rethrow it.
printToStderrFinalizerExceptionHandler :: SomeException -> IO ()
-- See Note [Handling exceptions during Handle finalization] in
-- GHC.IO.Handle.Internals
printToStderrFinalizerExceptionHandler se =
hPutStr stderr msg `catchException` (\(SomeException _) -> return ())
where
msg = "Exception during weak pointer finalization (ignored): " ++ displayException se ++ "\n"
|