public static int parseInt(String s) throws NumberFormatException
发现在此方法中有throws 关键字,那么既然有此关键字,则意味首程序中应该使用 try....catch 进行处理操作
package org.exceptiondemo;
public class ExceptionDemo01 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer.parseInt("123");
}
}
但是,在使用时发现程序中根本就没有必要进行异常的处理
NumberFormatException 是 RuntimeException 的子类
那么也就是说只要是RuntimeException 的异常对象,虽然使用了throws,但是在程序中也可以不使用try...catch进行处理