如何忽略 Eclipse 中特定类型的未捕获异常?

发布于 2024-10-20 05:06:51 字数 859 浏览 2 评论 0原文

我在我的 Java 应用程序中使用第三方库。这个第三方库在每次应用程序启动时都会引发自定义的未捕获异常。该异常是无害的,仅用于第三方库内部记录的目的。由于未捕获此异常,它会导致我的 Eclipse IDE 切换到调试视角,并在每次启动应用程序时暂停线程执行以通知我该问题。我必须手动告诉 Eclipse 忽略这个并每次都恢复调试。这很烦人。我无法更改第三方库来解决此问题。

有没有办法告诉 Eclipse IDE 忽略特定类型的未捕获异常?

我尝试了“步骤过滤”,但是(我认为)由于自定义未捕获的异常不在堆栈跟踪中,因此它不会从调试器中过滤掉。这是我第一次尝试逐步过滤,因此我可能会错误地使用它。这是堆栈跟踪示例。

Daemon Thread [Thread-13] (Suspended (exception CustomThirdPartyException)) 
    ThreadPoolExecutor$Worker.run() line: not available [local variables unavailable]   
    Thread.run() line: not available

编辑:

jluzwick 在禁用 Eclipse 中所有未捕获的异常后使用我们自己的记录器来监视未捕获的异常的工作在技术上可以工作,但它并不理想,如果我们的记录器损坏,我们可能会错过一些东西。

mazaneicha 的解决方案似乎走在正确的轨道上,但我无法让它完全按照我想要的方式工作。这可能是由于我的用户错误造成的。

jluzwick 和 mazaneicha 都有可能解决这个问题,但 Konstantin Komissarchik 给出了“正确”的答案,因为这个问题应该被推回给库的创建者来修复。有时技术解决方案并不正确。

I am using a third party library in my Java application. This third party library throws a custom uncaught exception at every application startup. The exception is harmless and only used for logging purposes internally to the third party library. Since this exception is not caught it causes my Eclipse IDE to switch into the debug perspective and suspend the thread execution everytime I start the application to inform me of the issue. I have to manually tell Eclipse to ignore this and just resume debugging every time. This is very annoying. I cannot change the third party library in order to fix this issue.

Is there a way to tell the Eclipse IDE to ignore a specific type of uncaught exception?

I tried "Step Filtering" but (I think) since the custom uncaught exception is not in the stack trace it is not being filtered out from the debugger. This is my first foray into Step Filtering so I could be using it wrong. Here is a sample stack trace.

Daemon Thread [Thread-13] (Suspended (exception CustomThirdPartyException)) 
    ThreadPoolExecutor$Worker.run() line: not available [local variables unavailable]   
    Thread.run() line: not available

EDIT:

jluzwick's work around of using our own logger to watch for uncaught exceptions after disabling all uncaught exceptions in Eclipse could technically work but it is not ideal and it's possible we could miss things if our logger is broken.

mazaneicha's Solution seemed to be on the right track but I could not get it to work exactly the way I wanted. This may be due to user error on my part.

jluzwick and mazaneicha both had possible work arounds to this issue but Konstantin Komissarchik had the "correct" answer in that this should be pushed back to the library's creators to fix. Sometimes a technical solution is not the right one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

扛起拖把扫天下 2024-10-27 05:06:51

一个旧线程,但我想我会添加一些内容。

至少在 Eclipse Indigo 中:在“调试透视图”->“断点”视图中:

  1. 为要暂停的异常(以及可能的子类)指定断点。这是通过单击“添加 Java 异常断点”来完成的。由 J 和感叹号组成的图标。
  2. 右键单击断点并选择“断点属性”
  3. 转到“过滤”
  4. 指定要忽略的类或包。这会将它们添加到列表中。只需确保取消选中它们以表明它是独占的(不要在指定位置停止)

我倾向于使用它,以便我可以将 NullPointerExceptions 指定为通用异常断点,但忽略来自第三方库的包。

An old thread, but figured I'd add a bit to it.

In at least Eclipse Indigo: In the Debug Perspective->Breakpoints view:

  1. Specify a breakpoint for Exceptions (and potentially subclasses) you want to pause on. This is done by clicking the "Add Java Exception Breakpoint". An icon that is a J and an exclamation point.
  2. Right click the breakpoint and select "Breakpoint Properties"
  3. Go to "Filtering"
  4. Specify the Class or Packages you want to ignore. This will add them to the list. Just be sure to uncheck them to delineate that it's exclusive (do not stop in the specified location)

I tend to use this so that I can specify NullPointerExceptions as a general exception breakpoint, but ignore packages that are from third party libraries.

好菇凉咱不稀罕他 2024-10-27 05:06:51

我建议尝试用代码来解决这个问题。在代码中找到初始化此库的位置并捕获此异常,而不是让它在堆栈中传播,这不被视为“正常”行为。

I would recommend trying to solve this in code instead. Find the place in your code where you are initializing this library and catch this exception instead of letting it propagate up the stack, which is not considered "normal" behavior.

音盲 2024-10-27 05:06:51

你试过这个吗?

转到“窗口”->“首选项”->“Java”->“调试”,

在“暂停执行”下取消选中“在未捕获的异常上暂停执行”

我不确定是否有办法禁用特定异常,但我可能是错的。可能有一个插件可以做到这一点。

Have you tried this?

Go to Window->Preferences->Java->Debug

Under "Suspend Execution" uncheck "Suspend Execution on uncaught exceptions"

I'm not sure there's a way to disable for specific exceptions, but I could be wrong. There might possibly be a plugin that does it.

若有似无的小暗淡 2024-10-27 05:06:51

在“调试”透视图的“断点”视图中,单击“Java 异常断点”(带有小写字母 J 和感叹号 J!的图标)。在出现的“添加 Java 异常断点”窗口中,您可以找到烦人的异常并取消选中“挂起未捕获的异常”框。

In Debug perspective, Breakpoints view, click on Java Exception Breakpoints (an icon with small letter J and exclamation mark, J!). In the appearing Add Java Exception Breakpoint window, you can find your annoying exception and uncheck "Suspend on Uncaught Exception" box.

晌融 2024-10-27 05:06:51

为杰夫的回答做出贡献:

在“调试”视角中,右键单击挂起的线程并选择“排除异常位置”。这样,Eclipse 将线程挂起的类添加到未捕获异常的过滤列表中。

Contributing to Jeff's answer:

In Debug perspective right click on the suspended thread and choose 'Exclude Exception Location'. This way Eclipse adds the class the thread suspended on to the filtering list of the uncaught exception.

蓬勃野心 2024-10-27 05:06:51

听起来你需要一个简单的尝试,抓住。

 MyException e = new MyException;
 try {
       throw new e;
 } catch (MyException e) {
       e.printStackTrace();
 } 

这将允许抛出异常,但会忽略并让程序继续运行。如果您希望将其记录到文件中,请使用“PrintWriter.println(e.printStackTrace());”

我希望您得到了您需要的东西,并祝您编码愉快!

You sound like you need a simple try , catch.

 MyException e = new MyException;
 try {
       throw new e;
 } catch (MyException e) {
       e.printStackTrace();
 } 

This will allow the exception to be thrown, yet will ignore and let the program continue. If you want it to be logged to a file, use 'PrintWriter.println(e.printStackTrace());'

I hope you got what you needed, and happy coding!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文