Throw exception inside catch clause

前端 未结 7 989
悲哀的现实
悲哀的现实 2021-01-12 15:34

I have two snippet of code :

class PreciseRethrow {
public static void main(String[] str) {
    try {
        foo();
    } catch (NumberFormatException ife)          


        
7条回答
  •  醉酒成梦
    2021-01-12 16:19

    The compiler can determine in the case of throw e, that it can only be a checked exception of type NumberFormatException which is already declared in the throws clause.

    In the latter case you're trying to throw the checked Exception which needs to be declared in the throws clause or caught.

提交回复
热议问题