开发者

Making Eclipse show the topmost exception in its console instead of the full stack trace

开发者 https://www.devze.com 2023-02-19 19:51 出处:网络
Is there a way to make Eclipse show up in its Console the \"top\" exception instead of just printing all the stack trace and leaving me always with the screen filled with basically useless stuff? Here

Is there a way to make Eclipse show up in its Console the "top" exception instead of just printing all the stack trace and leaving me always with the screen filled with basically useless stuff? Here's a picture:

Making Eclipse show the topmost exception in its console instead of the full stack trace

There are basically 2 things I might want to know in 99% of the times when there's an exception: it's name+message plus in which method it ocorred. None of them is visible without having to scroll up. This is how 开发者_JS百科I feel the data should be shown:

Making Eclipse show the topmost exception in its console instead of the full stack trace

Is there a way to change this Eclipse's behaviour?


  1. I know of no Eclipse feature that will do this.

  2. I disagree that the IDE should do this. There's no way for the IDE to know what information in the stacktrace is useful or useless. Scrolling the console to the supposedly useful part of the stacktrace based on some heuristic might help you a little bit today, but tomorrow it might hinder you a lot. And the problem / danger is likely to be worse if you start folding or editing the stacktrace displayed in the console window.

Use the scrollbar Luke!


If you really think this would be a good idea, implement it and submit a patch to the Eclipse developers. Or create a plugin. Or use a different IDE.


By the way, the screenshot you included in your comment does not show an IDE scrolling a console window. Rather it is showing an exception that has actually been delivered to the IDE as-is. Eclipse can do this too ... to some degree ... as illustrated by the JUnit test view, the Error view and so on. But this doesn't work if the stack trace has been rendered as text and written to a console window. (For a start, the text format of a stack trace is not actually specified.)


I don't think there is a way in Eclipse to do this.

But I think the IDE actually has nothing to do with this. It is the JVM that is printing that output to the console since your program isn't catching the exception. If you ran it from command line, you would see the same output.

I think the program should handle the exception and print the desired level of information to the console.


Indeed, the IDE has nothing to do with this. And you might want to rephrase that opinion as sometimes the useful information is not always the last executed line, but somewhere deeper in the stack trace (ex: an invalid value is passed to a method, down to the nth level where the exception occurs.)

Eclipse can't change this behavior as this is a run-time behavior of the JVM; when the exception is not catch, System.err is used to output the stack trace. You can change this by replacing the error output stream.

The PrintWriter that you set could keep the original copy of System.err and simply discard anything you don't care (i.e. anything matching "^\s*(java(x?)\.).*", or something) But the work around is not worth the trouble.

The better solution would be to catch and handle your exceptions and output something useful instead. The Java API is pretty explicit when some method throws an exception. There should be no surprise there.

Or another solution would be to avoid exceptions at all and be glad that Java prints a much useful stack trace to begin with and help you debug your application. Many language actually don't do that (or just not as good). If and when you deploy an application to a client, you'll actually be glad that the user sends you the complete stack trace instead of just a one-liner where the exception occurred.


You can use an eclipse plugin like grepclipse or GerpConsole to filter console's output with regular expresions.

0

精彩评论

暂无评论...
验证码 换一张
取 消