public class ExceptionTest
{
public void method()throws Exception
{
System.out.println("deal with the exception");
throw new Exception();
}
public static void main(String args[])throws Exception
{
//方法一:通过调用方法的方法向上一层抛出,最后由JAVA虚拟机去捕获
//ExceptionTest test=new ExceptionTest();
//test.method();
//方法二:通过try catch finally 进行异常捕获处理
ExceptionTest test=new ExceptionTest();
try
{
test.method();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("the exception has been dealed");
}
}
}
异常处理的两种方法
最新推荐文章于 2022-05-16 20:11:41 发布