首页 新闻 会员 周边

Throw java为什么提示错误

0
悬赏园豆:5 [已解决问题] 解决于 2018-06-08 22:48

public class Defind {
public static void main(String[] args) {
try
{
throw new DefindException("异常");
}
catch(DefindException e)
{
System.out.println(e);
}
}

class DefindException extends Exception
{
public DefindException(String msg)
{
super(msg);
}
}
}

烧鸭的主页 烧鸭 | 初学一级 | 园豆:101
提问于:2018-06-04 23:29
< >
分享
最佳答案
0

class DefindException增加static就行了

static class DefindException extends Exception

内嵌类的实例化

收获园豆:5
2012 | 高人七级 |园豆:21230 | 2018-06-05 08:29
其他回答(2)
0

楼上说的对

peachyy | 园豆:243 (菜鸟二级) | 2018-06-05 10:13
0

一种throw new Defind().new DefindException("异常");
一种static class DefindException extends Exception
一种class DefindException extends Exception{public DefindException(String msg){super(msg);}}这段代码挪到Defind类代码外部

、熙和 | 园豆:1508 (小虾三级) | 2018-06-06 09:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册