I'm new to thread programming, and am kind of working on a monkey see monkey do approach.
I have a reasonably sized program that runs multiple threads, and am wondering how to catch the runtime exceptions.
The code below catches the runtime error and displays the message in a gui. I'm running the program in eclipse, and have noticed that when the dialog box is closed, the process continues to run. How should the program be modified to stop running when the exception dialog is closed?
I thought that adding Thread.currentThread().interrupt(); to the close action listener would do the trick, but the process is still running...
Your class 'ThreadExceptionHandler' is just a Runnable and not a Thread. You are not starting a thread anywhere. By calling SwingUtilities.invokeLater, you are just adding a piece of Runnable to be placed in the EDT queue (Swing's Event Thread). The process continues to be running because, in the close button, you only make the dialog invisible. Instead, call dispose() on the dialog to close it. Then the process will end.
SCJP 1.4, OCMJEA/SCEA 5.0.
Joined: Sep 26, 2010
subject: Suggestions for catching runtime in run function