Rethrow exception in java

后端 未结 7 1526
情书的邮戳
情书的邮戳 2020-12-06 06:41

I have a very simple question about re-throwing exception in Java.

Here is the code snippet:

public static void main(String[] args) throws FileNotFou         


        
7条回答
  •  有刺的猬
    2020-12-06 06:48

    In the example given, re-throwing the Exception serves no purpose.

    Doing this can be useful if the method that catches and then re-throws the exception needs to take some additional action upon seeing the Exception, and also desires that the Exception is propagated to the caller, so that the caller can see the Exception and also take some action.

提交回复
热议问题