[Haskell-cafe] Control.Exception.bracket is broken(?)
mwm at mired.org
Sun Jul 6 13:37:29 UTC 2014
On Jul 6, 2014 8:15 AM, "Yuras Shumovich" <shumovichy at gmail.com> wrote:
> 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
> 1) suppress the exception from release action and rethrow the original
> 2) shutdown the program
> 3) suppress the original exception and throw the exception from release
> 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
> - 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)
You left off what I think is the best behavior, from Python 3:
4) Throw the exception for the release action, chaining the original
exception to it. The default exception handler reports the them both.
> I prefer #2 because suppressing exception is a really bad idea. What is
> your choice?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe