1 //异常类 2 package st; 3 public class example_1 4 { 5 public static void main(String args[]) 6 { 7 int n=0,m=0,t=1000; 8 try 9 { 10 m=Integer.parseInt("8888"); 11 n=Integer.parseInt("ab89"); 12 t=7777; //t没有机会被赋值 13 } 14 catch(NumberFormatException e) 15 { 16 System.out.println("发生异常:"+ e.getMessage()); 17 } 18 System.out.println("n="+n+",m="+m+",t="+t); 19 try 20 { 21 System.out.println("故意抛出I/O异常!"); 22 throw new java.io.IOException("我是故意的"); //故意抛出异常 23 24 } 25 catch(java.io.IOException e) 26 { 27 System.out.println("发生异常:"+e.getMessage()); 28 } 29 } 30 }
相关文章: