Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime Exception Display??  RSS feed

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had an error in a build this morning because a class hadn't been included in the jar.

As it was a swing application with no console when the ClassNotFoundException exception was throw it was never displayed to the user and the program just hangs.

I looked at overridding the ClassLoader to print the exception in a JDialog but it was to messy.

Does anyone know a nice way of handling such a problem? The program is unusable after the exception but the user should be politly informed.

Thanks

Kris
 
Stephen Boston
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about catching Java.lang.exception and displaying that in a JOptionPane?
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to catch major abnormalities like when a class can't be found.
If I was going to program that myself I would have to put every
(new className) in a try block.

I want do something like redirect the standard error to a JDialog rather then console. I don't think there is a clean solution for this.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there might be.

You could create your custom OutputStream, create a PrintStream using that and set that PrintStream using System.setErr. I've created an OutputStream that writes to a JTextComponent myself a while ago.
Only problem is that this does not tell you when to show the dialog. You could show the dialog upon flushing, the only problem is that no printStackTrace method of Throwable calls flush. But if you can find a solution for this than I think the problem is solved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!