在方法中直接try catch
public static void throwDemo(){
try{
//方法体;
}catch (Exception e){
System.out.println("运行时出现了异常:"+e.toString());
};
}
使用throws,在调用方法时try catch异常
public static void throwDemo() throws Exception {
//方法体;
}
public static void main(String[] args) {
try{
throwDemo();
}catch (Exception e){
System.out.println("运行时出现了异常:"+e.toString());
};
}