Questions tagged «unchecked-exception»

21
了解Java中的已检查异常与未检查异常
约书亚·布洛赫(Joshua Bloch)在《有效的Java》中说 将检查的异常用于可恢复的条件,将运行时异常用于编程错误(第二版中的项目58) 让我们看看我是否正确理解了这一点。 这是我对检查异常的理解: try{ String userInput = //read in user input Long id = Long.parseLong(userInput); }catch(NumberFormatException e){ id = 0; //recover the situation by setting the id to 0 } 1.以上是否被视为经过检查的异常? 2. RuntimeException是未经检查的异常吗? 这是我对未经检查的异常的理解: try{ File file = new File("my/file/path"); FileInputStream fis = new FileInputStream(file); }catch(FileNotFoundException e){ //3. …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.