在Eclipse中更改未处理的异常自动生成的catch代码? [英] Change unhandled exception auto-generated catch code in Eclipse?
问题描述
如果我选择(2)它添加一个代码
try {
myfunction();
} catch(MyUnhandledException e){
// TODO自动生成的catch块
e.printStackTrace();
}
我想将其更改为
try {
myfunction();
} catch(MyUnhandledException e){
throw new RuntimeException(e);
}
这是可能吗?
更新
为什么这么爱改变主题人物?
如果异常被捕获和打印,也不需要再抓住它。如果我忘记了错误处理异常,我喜欢我的应用程序崩溃。所以,我喜欢默认重新抛出。
是的,你可以更改Eclipse添加的默认代码。 >
- 在首选项中,导航到 Java>代码样式>代码模板。
- 在代码下,选择抓住块正文。
- 按编辑按钮更改代码。完成后,按
确定按钮。
考虑在默认情况下添加TODO注释抓块。例如,默认值包括:
// $ {todo}自动生成的catch块
If I have unhandled exception in Java, Eclipse proposes two options to me: (1) add throws declaration and (2) surround with try/catch.
If I choose (2) it adds a code
try {
myfunction();
} catch (MyUnhandledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I want to change this to
try {
myfunction();
} catch (MyUnhandledException e) {
throw new RuntimeException(e);
}
Is this possible?
UPDATE
Why are so love to change the topic people???
If exception is catched and printed it is also no need to catch it anymore. I like my application to crash if I forget to handle an exception by mistake. So, I like to rethrow it by default.
Yes, you can change the default code added by Eclipse.
- In Preferences, navigate to Java>Code Style>Code Templates.
- Under Code, select Catch block body.
- Press the Edit button to change the code. When finished, press the OK button.
Consider adding a TODO comment in the default catch block. For example, the default includes:
// ${todo} Auto-generated catch block
这篇关于在Eclipse中更改未处理的异常自动生成的catch代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!