Java 7 - Precise rethrow with a final Exception

前端 未结 3 811
礼貌的吻别
礼貌的吻别 2021-01-01 12:47

In previous versions of java, rethrowing an exception was treated as throwing the type of the catch parameter.

For example:

public static void test()         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 13:01

    I believe I saw a tweet from Josh Bloch saying that the "final" restriction had been lifted late on. I'll see if I can find a post about it, but I suspect it's just that any "early" documentation you read is now inaccurate.

    EDIT: I can't find the exact "it's changed" post, but the Java 7 documentation states shows an example with it not being final. It talks about exception variables being implicitly final when a catch block declares more than one type, but that's slightly separate.

    EDIT: I've now found the source of my confusion, but it's an internal mailing list post :( Anyway, it doesn't have to be declared as final, but I believe the compiler treats it as implicitly final - just like in the multi-catch scenario.

提交回复
热议问题