Java异常处理 - 自定义异常 [英] Java exception handling - Custom exception
本文介绍了Java异常处理 - 自定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的自定义异常
I have a custom exception like this
public class MyOwnException extends Exception {
}
然后在我的课上
我有两个方法
public void ExceptionTest() throws Exception {
throw new FileNotFoundException();
}
public void ApplicationExceptionTest() throws MyOwnException {
throw new FileNotFoundException();
}
Eclipse抱怨第二种方法未处理的异常类型FileNotFoundException。我以为因为MyOwnException扩展了异常,它不应该抱怨...
Eclipse complains about the second method 'Unhandled exception type FileNotFoundException'. I thought since MyOwnException extends Exception it shouldnt complain...
任何人都可以告诉我我在这里缺少什么?
Can anyone tell me what I am missing here?
推荐答案
扩展树
- 异常
- IOException
- FileNotFoundException
FileNotFound和MyOwn不相识。
FileNotFound and MyOwn did not know each other.
public void ApplicationExceptionTest() throws Exception { throw new FileNotFoundException(); }
是要走的路
评论:
我希望这仅适用于模型测试,而不是实现您在常规来源中使用的类代码!
I hope this is for mockup testing only and not for implementing a class you wnt to use in your regular source code!
这篇关于Java异常处理 - 自定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- IOException
查看全文