可以在代码中将可能出现的异常抛出,交给上层(调用该方法的函数)处理。
public void testTrowException() throws FileNotFoundException{ FileInputStream fileInputStream = new FileInputStream("java.txt"); }
try { FileInputStream fileInputStream = new FileInputStream("java.txt"); fileInputStream.read(); //FileNotFoundException extends IOException //FileNotFoundException fileNotFoundException = new FileNotFoundException(); //IOException e = fileNotFoundException; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { }