Redian新闻
>
Ask a simple question about throw exception, bow bow bow
avatar
Ask a simple question about throw exception, bow bow bow# Java - 爪哇娇娃
r*c
1
I just have a piece of code as follows
public void methodA()
{
methodB(paramA, new Class() throws AException {
Noname class
}

}
According to common jave exception practice, should I also modify methodA to
throws AException?
avatar
t*s
2
yes, if you don't want to catch AException in methodA

【在 r****c 的大作中提到】
: I just have a piece of code as follows
: public void methodA()
: {
: methodB(paramA, new Class() throws AException {
: Noname class
: }
:
: }
: According to common jave exception practice, should I also modify methodA to
: throws AException?

avatar
g*g
3
Usually you don't extend RuntimException unless you want to
halt the system when the exception is throwed.
avatar
m*t
4

Technically, an uncaught exception does not halt the entire jvm (if that's
what you meant by "system"). If I'm not mistaken, it ends up killing the
thread throwing the exception - of course, if that thread happens to be the
main GUI thread in a Swing app, it would indeed appear to have halted the
entire system. 8-)

【在 g*****g 的大作中提到】
: Usually you don't extend RuntimException unless you want to
: halt the system when the exception is throwed.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。