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

前端 未结 7 1400
眼角桃花
眼角桃花 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:26

    It is bad practice to catch Exception -- it's just too broad, and you may miss something like a NullPointerException in your own code.

    For most file operations, IOException is the root exception. Better to catch that, instead.

提交回复
热议问题