异常有两类:exception和error
throw用于抛出一个异常,throws用于抛出很多异常
public class ThrowDemo{
public static void main(String args[])throws IOException{
....
}
}
pbulic class ThrowDemo{
public static void main(String args[]){
try{
try{
System.out.println("我要自己制造异常了.....");
throw new IOException("FirstException");
}catch(IOException a){
System.out.println("捕捉到了:"+a);
throw new NumberFormatException("SecondException");
}
}catch(NumberFormatException e){
System.out.println("我又捕捉到了:"+e);
}
}
}
阅读(588) | 评论(0) | 转发(0) |