eclipse console doesn't show the exception - java

"The default handler displays a string describing the exception, prints a
stack trace from the point at which the exception occurred, and terminates the program."
But this doesn't happen. Every time i intentionally create a DivideByZero exception but provide no exception handler, the default handler should have displayed a string with stack trace but my console is empty and program is not terminated only exception it shows is in debug panel. It may be small problem but every where i look the exception should have been printed in console but myconsole is empty.
I use eclipse neon.
Update from comment:
public class Example {
public static void main(String args[]){
System.out.println(10/0);
}
}
This should give ArithmeticException but there is nothing displayed at console.

If you Run the program, it will print stacktrace.
If you Debug the program, the debugger will (by default) halt execution when an uncaught exception is thrown, but it will (by default) not show the exception. Select Resume (F8) to continue execution, and the program will end and print stacktrace.
If you don't intend to debug the program, choose Run to start the program, not Debug.
If you want to debug, but don't want to halt execution on uncaught exception, open Window > Preferences, go to Java > Debug, and uncheck Suspend execution on uncaught exceptions.
If you still want to halt execution on uncaught exception, but you also want to actually see the exception, open Window > Preferences, go to Java > Debug, and check Open popup when suspended on exception. Source: Inspect current exception in Eclipse debugger?
Note: The above is from Eclipse Mars.2, not Neon, but should be the same.

Related

GWT Not showing root call trace on click exception

When handling a click event and an uncaught exception is thrown the console does not show the actual line of code where the exception is triggered. Instead, it looks like this:
Throwable.java:121 Uncaught Error: com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) : Cannot read property 'getNotificationsShortcuts_0_g$' of null
at iOi_g$.cve_g$ [as createError_0_g$] (Throwable.java:121)
at iOi_g$.mve_g$ [as initializeBackingError_0_g$] (Throwable.java:113)
at iOi_g$.Yue_g$ (Throwable.java:74)
at iOi_g$.Cve_g$ (Exception.java:33)
at iOi_g$.Kve_g$ (RuntimeException.java:33)
...
If I try/catch the code where the exception is thrown and print the caught exception by getting all the StackTraceElement items from e.getStackTrace(), it seems that the stack trace is displayed correctly (the root in my lines of code is displayed):
TypeError: Cannot read property 'getNotificationsShortcuts_0_g$' of null
at VCn_g$.fDn_g$ [as loadSavedShurtcuts_0_g$] (EMaterialNotificationsHeaderView.java:483)
at BCn_g$.HCn_g$ [as loadSavedShurtcuts_0_g$] (EMaterialNotificationsHeader.java:37)
at fFn_g$.gFn_g$ [as build_0_g$] (SDemoNotificationsHeader.java:51)
...
Is there a way to show set the logs so that the root call trace of the exception is displayed correctly when an event is triggered?
If an exception is directly caught, you will see the full stack trace. If an exception simply wraps another single exception, generally you'll see the stack trace as well.
But the UmbrellaException indicates that some event was going off when that exception was thrown. The event didn't just stop because of the exception (which would then cause other handlers to miss out on it), but instead the exception was noted, and the other handlers invoked. Once they were all finished, an UmbrellaException gets thrown, containing all of the exceptions that happened during the course of trying to fire that event.
Often this will only wrap a single exception, but the result is the same - the umbrella exception informs you that something went wrong, and the event finished informing all of its handlers, and then this was thrown to say that something went wrong.
If you are seeing this in your UnCaughtExceptionHandler (UCEH), then there was no try/catch around the fireEvent call itself.
Whether you catch it in the UCEH or in some other try/catch, once you test if it is an UmbrellaException, you can call exception.getCauses() to read all of the exceptions that occurred, and individually log each of them.

What does "Process finished with exit code 1" mean in intellij-idea?

I got the error "Process finished with exit code 1" when I was running my Java code. I am using Intellij IDEA 2018.3. Below is the error log I got.
While running a Java application in Intellij Idea, after the program execution, JVM prints the exit code to the console. If the program terminates without any exception, exit code 0 is printed. Otherwise, any signed integer may be outputted.
To get more information on the exit code try putting a try catch around the SpringApplication.run() function like this:
try
{
SpringApplication.run(Application.class, args);
}
catch (Throwable throwable)
{
System.out.println(throwable.toString());
throwable.printStackTrace();
}
For springboot projects, the most common reason is org.springframework.beans.factory.BeanCreationException.
Search BeanCreationException, debug at each construct function, and debug the projects.
Then you will find out the 'beanName' with problem, then you can focus on the bean.
for example:

JavaFX: How to show Alert without Stage for testing?

I use JavaFX for a GUI that waits for some user's input and tries to process that input. In case of any exception a javafx.scene.control.Alert is opened to present the exception to the user. The call for that Alert is done in the method that handles the exception.
This method is supposed to be tested: For a special input, check if the right exception is thrown. The right exception is actually thrown and the handling method is called, but now here's the problem: In the test case there is no real Application running and no Stage created. Apparently because of that the creation of the Alert-dialog throws the exception:
java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:550)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 46 more
That causes the test to fail because now another incorrect exception is thrown.
So: Is there any way to show the Alert without having a Stage?

Eclipse breaks on processWorkerExit

After serving a few requests my eclipse has started breaking on processWorkerExit() method.
As per this link I know how to suppress the breaking of eclipse but is there any reason why the code is breaking on this line. Can there be a memory leak in such a case?
Tomcat 7.0.27
Eclipse 3.7.2
JDK 7.0.02
Answer is here: OpenJDK breaks on processWorkerExit with no breakpoint
In debug mode in eclipse by default, break on uncaught exceptions is
checked. Since you don't have a catch method here, it's likely that an
uncaught exception is being thrown and the debugger is breaking for
you immediately before the exception is thrown. You can turn it off in
preferences under Java->Debug.
The reason the debugger is stopping on that line is because there is an exception being thrown by the code within the try{} block, and that particular line of code is the next executable line of code after the exception is thrown. You can almost certainly see the stack trace of that exception in the console window, because by default an uncaught exception that bubbles up to Thread.run() will be sent to stderr.
As for your question about whether there can be a memory leak (or more likely, this being Java, a resource leak): the answer is yes, there could be. But there is nothing in that code to indicate that there is. If there were such a leak, it would almost certainly be because there is incorrect exception handling inside the task implementation.
I had this same problem. It breaks in your try/catch clause if you have one if you don't log the exception. Try inserting a breakpoint or output to LogCat like this :
try
{
//HERE I'VE PUT ALL THE FUNCTIONS THAT WORK FOR ME
Log.e("tag", "Sth passed!");
}
catch (Exception e)
{
//The task failed
Log.e("tag", e.getMessage());
}
If you don't have try/catch block put it like in above code. In LogCat you can see the last line of code that was run before exception it will help you to locate the error in your code just like this :
08-28 05:49:52.321: E/SQLiteDatabase(834): at java.lang.Thread.run(Thread.java:841)

Eclipse/Java: uncaught exceptions on the EDT suspend execution in EventDispatchThread.run()

This is a minor annoyance I have when debugging with Eclipse. With "Suspend execution on uncaught exceptions" checked, the debugger will normally suspend a thread right where the exception was thrown. Exceptions on the Event Dispatch Thread, however, cause it to pause on the last line of EventDispatchThread.run(). There is no useful information about what the exception is or what caused it until I resume the thread to allow the stack trace to print to the console.
Debug the following code in Eclipse to demonstrate:
public class SuspendOnUncaughtTest {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
((Object) null).toString();
}
});
}
}
And here is what it looks like after the exception is thrown:
EDIT 10/21/2011: I guess there's nothing weird going on with Eclipse or the Java debugger, it's just that exceptions are caught and rethrown in EventDispatchThread.pumpOneEventForFilters(int). I suppose there's no way to tell Eclipse to "suspend execution on exceptions that are going to be caught and possibly rethrown". Too bad.
Is see a similar result in NeteBeans, but Thread.setDefaultUncaughtExceptionHandler() may be useful in this context. There's an example here.
As far as I can tell, there is no solution to this. Eclipse is behaving correctly, the correct behavior is just annoying.
I had this issue and found something that worked for me.
I am using Kepler, and was able to stop this by going to the breakpoints tab of the debugger perspective and deselecting the checkbox on the EventDispatchThread.

Categories

Resources