How can I handle an IOException which I know can never be thrown, in a safe and readable manner?

后端 未结 8 1814
生来不讨喜
生来不讨喜 2021-02-02 12:07

\"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong go

8条回答
  •  别跟我提以往
    2021-02-02 12:57

    If your position is that this is so unlikely and should just end the program, use an existing runtime exception, even RuntimeException itself (if not IllegalStateException).

    try {
      ....
    
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }
    

提交回复
热议问题