[/quote]
[quote]class Demo
{
int div(int a,int b) //throws Exception
{
return a/b;
}
}
class ExceptionDemo
{
public static void main(String[] args)
{
Demo d = new Demo();
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");
}
}
QQ截图20120717155858.gif (2.15 KB, 下载次数: 63)
百思不得其姐
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |