I have read a few posts on here about overriding the default exception with Thread.setDefaultUncaughtExceptionHandler but when I try to this this I had problems in Eclipse.
If I have some code which normally throws an exception and is currently surrounded by a try/catch block and I want to remove this and let my own handler deal with it, Eclipse won't let me remove the try/catch blocks as it complains that i开发者_如何学Ct can't compile and suggests enclosing the code in a try/catch block. I can't use throws to propagate the problem out of the method as this just has the same problem wherever it calls the method.
Do I need to switch off some compile time error checking in Eclipse so it ignores these issues or is there another way to deal with this?
Checked Exceptions have to either be caught or declared that they will be thrown in your method signature. That's what Eclipse is complaining about.
If you throw the Exception all the way up to the top of the chain it will be handled by the Thread.setDefaultUncaughtExceptionHandler.
Unchecked exceptions do not have this requirement (exceptions that extend RuntimeException
).
精彩评论