I’ve seen some code as below in some example BlackBerry Java classes:
try
{
// stuff that will throw an exception
}
catch(final Exception e)
{
// deal with it
}
I presume the final is for performance. As per the title, since there’s rarely (ever?) any reason to modify an Exception that’s already been thrown, should they always be final?
If so, isn’t this something that could be done by the compiler? Or is it done by the compiler and adding the final manually has no impact at all?
The Java Language Specification 11.2.2 makes a difference between final and not final exceptions:
Interestingly, JLS 14.20 also says:
In other words, if you don’t reassign the
eof your catch statement (likee = new SomeOtherException();), it is implicitly declared final.So I can only conclude that it does not make a difference, unless the exception is modified in the catch block and the only example I can come up with is: