Especially when making extensions that include resources (like file handles or locks), the current system of handling exceptions can be a bit clunky when trying to make sure those resources are repatriated.
The current pattern I am using is somewhat like this:
It's awkward in large part because not only does the cleanup have to be duplicated for the regular path and all exception handlers, but there is no opportunity to "re-raise" the original exception.
Perhaps something like this would be in order?
That would generate a try..finally around the code, with the Cleanup part of the flowchart in the Finally section.
If the try..finally was generated *inside* the regular try..catch, then the exception handlers could also catch issues that get raised in the cleanup.