一个关于JAVA 异常的小问题?

[复制链接]
查看11 | 回复3 | 2009-5-9 19:54:28 | 显示全部楼层 |阅读模式
public class TestException {
public static void main(String [] args) {
TestException te = new TestException();
te.m(0);
void m(int i)throws ArithmeticException{
if(i==0)
throw new ArithmeticException("被除数为0");
}
}
}
我这个抛出的异常哪个地方错了呢?我们老师就是这样写,没有看到它出错的呀?我说的是编译出现错误,不是运行的啊?

回复

使用道具 举报

千问 | 2009-5-9 19:54:28 | 显示全部楼层
你的m()方法是在main()方法里面应该是放在main()方法外面得:public class TestException { public static void main(String [] args) {TestException te = new TestException(); te.m(0); } //这个地方改了void m(int i)throws ArithmeticException{ if(i==0) throw new ArithmeticException("被除数为0"); } } //这里的"}"移上去了...
回复

使用道具 举报

千问 | 2009-5-9 19:54:28 | 显示全部楼层
void m(int i)这个方法你放在main中了。public class TestException { public static void main(String [] args) { TestException te = new TestException(); te.m(0); }void m(int i)thr...
回复

使用道具 举报

千问 | 2009-5-9 19:54:28 | 显示全部楼层
public class TestException { public static void main(String [] args) { TestException te = new TestException(); //te.m(0); } public void m(int i)throws ArithmeticExc...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行