Is there ever a reason to not use the final keyword when catching an exception?

后端 未结 5 920
萌比男神i
萌比男神i 2020-12-16 12:03

I\'ve seen some code as below in some example BlackBerry Java classes:

try
{
    // stuff that will throw an exception
}
catch(final Exception e)
{
    // de         


        
5条回答
  •  执笔经年
    2020-12-16 12:25

    I doubt final would really give any performance benefit because the exception instance is block local (Here is a really good answer explaining it https://stackoverflow.com/a/306966/492561).

    So It merely serves as a explicit marker that says I will not modify.

    Some times you may need to modify the exception to throw it back, may be edit the message to make it more clear at higher levels.

    Essentially I would say that its a matter of preference, Some may like it others may not.

提交回复
热议问题