[Haskell-cafe] Control.Exception.bracket is broken(?)

Yuras Shumovich shumovichy at gmail.com
Sun Jul 6 13:15:38 UTC 2014


Hello,

>From docs: "If an exception is raised, then bracket will re-raise the
exception (after performing the release)."

But what if the release action will throw an exception? There are 3
options:
 1) suppress the exception from release action and rethrow the original
one
 2) shutdown the program
 3) suppress the original exception and throw the exception from release
action.

Current behavior is #3 -- suppress the original exception. I think it
the worse choice.

What other languages do:

 - java has try-with-resources statement which is the nearest equivalent
of haskell's "bracket". It uses the option #1 (rethrow the original
exception)

 - in c++ it is common to use RAII for resource management, so someone's
destructor performs resource cleanup. But if destructor throws exception
during stack unrolling, the program is terminated (option #2)

I prefer #2 because suppressing exception is a really bad idea. What is
your choice?

And the related thing. Release action should not use any interruptible
action. Otherwise async exception can occur while processing other
exception, so one of them will be suppressed. Is it correct?
Control.Exception module contains a list of uninterruptible actions (see
"Interruptible operations" section), and e.g. "hClose" is not there. Is
"hClose" interruptible or not? If async exception interrupts "hClose",
the file descriptor will leak. So, should we use uninterruptibleMask in
release action for "bracket"?

Thanks,
Yuras



More information about the Haskell-Cafe mailing list