How can I catch all the exceptions that will be thrown through reading and writing a file?

前端 未结 7 1394
眼角桃花
眼角桃花 2020-12-02 13:46

In Java, is there any way to get(catch) all exceptions instead of catch the exception individually?

7条回答
  •  伪装坚强ぢ
    2020-12-02 14:41

    Do you mean catch an Exception of any type that is thrown, as opposed to just specific Exceptions?

    If so:

    try {
       //...file IO...
    } catch(Exception e) {
       //...do stuff with e, such as check its type or log it...
    }
    

提交回复
热议问题