Throw exception inside catch clause

前端 未结 7 911
悲哀的现实
悲哀的现实 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:29

    In the first code snippet, you are re-throwing the NumberFormatException that could possibly come up. In the second code snippet, you are throwing just general Exception, which is not NumberFormatException, as the method has declared.

提交回复
热议问题