Unchecked exceptions thrown into a GUI application

We know that uncontrolled exceptions should be used in case of violation of the method contract. If the application is running in the console, an exception will appear in the console window along with its stack trace. This is true even for a GUI application (such as written in Swing) called from the console, and the console runs in the background.

But what happens if the GUI application does not have a console? For example, the user double-clicks the link, and the application launches directly, without any console in the background. Where will unchecked exceptions be thrown?

The reason for this question is because some developers are trying to justify detecting thrown exceptions based on the above scenario.

+3
source share
5 answers

I believe that exceptions caused by the GUI thread that cannot go to the console are completely eliminated. They do not go anywhere.

, " ". - , .. , Java, .. - . (, Java Number , .)

GUI -, , . , . Java , GUI - , . Thread.setDefaultUncheckedExceptionHandler(), , System.setProperty("sun.awt.exception.handler", "string-that-names-exception-handler-class"), . , Thread.UncaughtExceptionHandler.

EDIT: AKF , stderr. , stderr ; stderr stdout . - , , , . , - , , , , .. , , , log4j, java.util.logging - , .

+2

, stderr, , . , . , , . .

+2

, stdout, , .

+1

stderr. stderr ( stdout) .

+1

In OS X, error messages in GUI applications are added to the system log, which can be viewed in the console application. I don’t know if this happens specifically for exceptions in Java applications, but I think so, and it’s easy to check if you have any of them.

I do not know about other operating systems.

I agree with other posters that you should redirect them to a file yourself.

0
source

Source: https://habr.com/ru/post/1719782/


All Articles