• Post Reply Bookmark Topic Watch Topic
  • New Topic

Catching all possible exceptions in gui thread  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have such a problem: I am developing Swing app and sometimes it crashes by throwing an Exception which I don't catch. The effect is that this exception prints stack trace on System.err but user is not notified and wonders what is happening... I would prefer to show custom ErrorDialog with stacktrace.
I am searching for simple and effective way to catch every possible exception thrown from within any library. I think of a few ways from which everyone has some disadvantages.
The ideal way would be replacing AWT event queue dispatcher so I could process every GUI event inside try { } catch (Exception e) {} block. That would be a good place to catch all exceptions. Unfortunately I don't know if it is possible.
For now I am trying such a solution:
I start background thread together with main app. Then I redirect System.err and System.out streams to PipedStream connected to this background thread. This thread can analyze anything that is going to System.err and maybe recognize potential exception stacktraces. Then it can notify main thread of an exception. But it is not ideal as I have to parse the stream and it can always be not ideal in exception recognition. And the code is quite costly.
Do you have any ideas, had similar problems?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps I am missing something here, but why not just test your application and whenever anything goes wrong, add a catch statement for that exception and handle it?
Also, you could try to isolate sections of your code that are more prone to throwing exceptions and add a try {} catch (Exception e) { System.out.println(e);} around each of them, then when something goes wrong, your application doesn't crash and you are notified of the error.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!