Eclipse不再检测丢失的try / catch吗? [英] Eclipse does not detect missing try/catch anymore?

查看:93
本文介绍了Eclipse不再检测丢失的try / catch吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此代码中

String a = "notANumber";
Integer b = Integer.parseInt(a);

由于 parseInt ,因此必须尝试/捕获抛出 NumberFormatException 异常。

在我以前的Eclipse版本中,我曾经收到警告,告诉您必须进行try / catch,但是我可以t想出了如何在当前版本的Eclipse上启用它

A try/catch is necessary since parseInt throws an NumberFormatException exception.
In my previous version of Eclipse, I used to got a warning telling that a try/catch was necessary but I can't figured out how to enable it on my current version of Eclipse which is

Eclipse Java EE IDE for Web Developers.
Version: Kepler Service Release 1


推荐答案

A NumberFormatException RuntimeException

您不要必须 try / catch 放入运行时异常。

You don't have to put try/catch for runtime exceptions.

来自 RuntimeException的javadoc


RuntimeException是在运行期间抛出
的那些异常的超类Java虚拟机的正常运行。
RuntimeException及其子类是未经检查的异常。

RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. RuntimeException and its subclasses are unchecked exceptions.

未经检查的异常无需在方法或
构造函数的throws子句中声明,只要它们可以由
的执行抛出方法或构造函数,并传播到方法或
构造函数边界之外。

Unchecked exceptions do not need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

我严重怀疑任何版本的Eclipse都需要 try / catch 来显示您的代码。您必须与另一个调用相混淆(也许是包装器声明了异常,未检查异常的事实并不意味着您有时不应该明确地捕获它,实际上,这通常是最明确地捕获的)

And I seriously doubt any version of Eclipse required a try/catch for the code you show. You must be confused with another call (maybe a wrapper one declaring the exception, the fact the exception isn't checked doesn't mean you shouldn't, sometimes, explicitly catch it, in fact this one is probably most often explicitly catched).

这篇关于Eclipse不再检测丢失的try / catch吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆