Why is it legal to re-throw a Throwable in certain cases, without declaring it?

后端 未结 3 1035
长发绾君心
长发绾君心 2020-12-09 03:08

I would expect the following code to raise a compile-time error on throw t;, because main is not declared to throw Throwable, but it c

3条回答
  •  醉梦人生
    2020-12-09 03:22

    When you catch Throwable or Exception and the variable is effectively final you can rethrow the same variable and the compiler will know which checked exceptions you could have thrown in the try {} catch block.

提交回复
热议问题