Rethrow exception in java

后端 未结 7 1546
情书的邮戳
情书的邮戳 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:59

    In addition to wanting to do something with the exception before exiting - like logging, the other time you would do something like that is if you want to wrap it as a different exception, like:

    try {
        FileReader reader = new FileReader("java.pdf");
    } catch (FileNotFoundException ex) {
        throw new ServletException(ex);
    }
    

提交回复
热议问题