//copyright©liupengcheng
//http://www.cnblogs.com/liupengcheng/*
//copyright©liupengcheng
* 异常的处理
* try
* {
* 需要被检测的代码
* }
* catch(异常类 变量)
* {
* 处理异常的代码(处理方式)
* }
* finally
* {
* 一定会执行的语句
* }
* */
//http://www.cnblogs.com/liupengchengclass Demo3
//copyright©liupengcheng
{
int div(int a,int b) throws Exception //声明函数有可能出现异常
{
return a/b;
}
}
//http://www.cnblogs.com/liupengcheng
public class ExceptionDemo {
public static void main(String [] args)
{
Demo3 d = new Demo3();
try
{
int x = d.div(4,0);
System.out.println("x"+ x);
}
catch(Exception e)
{
System.out.println("除零了");
System.out.println(e.getMessage());
}
System.out.println("over");
//copyright©liupengcheng
}
}
//http://www.cnblogs.com/liupengcheng