智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...

导航

java异常

Posted on 2009-11-23 11:46  Bill Yuan  阅读(172)  评论(0编辑  收藏  举报

 

//函数抛出异常 ———— 注意捕捉异常时 finally 的使用:
//1、关闭打开的文件
//2、删除临时的文件
//
void m(int i) throws ArithmeticException
{
  
if(i == o)
  {
    
throw new ArithmeticException("除数为0")
  }
}
void f() throws FileNotFoundException , IOException
{
  
FileInputStream in = new FileInputStream ("myfile.txt")
  
}

//处理
try 

   
new TextEx().f2(); 
catch (IOException e) 

   e.printStackTrace(); 
}