Universal Runtime Exception Catcher.

Is there a way to 'send' all Runtime Expections of a program to a single exception handler? (without having to hard code a lot of try/catch code)P.S. I think there might be something wrong with trying to do this... is there?Message was edited by: EvilBro
[284 byte] By [EvilBroa] at [2007-11-27 0:14:31]
# 1
There is a way to set the handler for all uncaught runtime exceptions. It might be in the System class.
tjacobs01a at 2007-7-11 21:59:51 > top of Java-index,Java Essentials,New To Java...
# 2

yep, if you're on java 1.5 or over. Thread.setDefaultUncaughtExceptionHandler() takes an instance of interface Thread.UncaughtExceptionHandler, which you must write a class to implement. it's only got one method on it, that takes the thread that the throwable was thrown from, and the throwable itself. nothing really wrong with doing it where appropriate. preferable a lot of the time to having a bunch of different developers handling fatal exceptions in different ways. but don't make the mistake of thinking you can just pass all your exceptions up the chain to this handler, that's not really what it's for. we use it to put a (relatively) friendly error dialog on-screen for anything we haven't handled elsewhere. the dialog has a "send to support" button which emails the stack trace etc. off to support when things go bang

georgemca at 2007-7-11 21:59:51 > top of Java-index,Java Essentials,New To Java...