Tony, that's not great, because you shouldn't let an exception escape a finally block, to stomp all over the exception that's already been thrown. Catch it and log it.
Practically, there's no reason not to use the 'null' version. Null isn't so much of a problem if it can't escape the current scope:
Of course, you can wrap this up to make nesting it less ridiculously complex. The only bits that really vary are the way to open a resource and the way to use it.
Which would be used like so:
Of course, there's only actually three lines of code in all that that are actually useful, and it seems a shame to have to have a separate SideEffectWithException as well as SideEffect.
You might think the above is poor code. It isn't, it's just code that's fighting against the language somewhat. Here's the same code in what Java 7 will likely look like:
Now it doesn't look so bad, does it?
[ inserted line breaks in overlong line of code - Jim ]
[ May 20, 2007: Message edited by: Jim Yingst ]