Short version: How do I catch all java.lang.Error
thrown in a particular section of code in order to log them, and also allow them to propogate up the call stack as if I hadn't caught them at all?
Long version...
In a section of code I want to catch all java.lang.Error
in order to log them. But I also want to let the Error
continue to work its way up the call stack so the behaviour would be the same as if I hadn't caught it at all.
Additionally, I want to catch and log all java.lang.Exception
s and then let them ALSO propogate up the call stack.
I tried this...
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
...but the problem with that is I have to modify every method higher up in the call stack to throw Throwable
, and some of those methods aren't mine to modify (my method is called by a method in a third party framework).
I would be happy with some kind of wrapping technique, whereby I would put the Throwable
in something else and throw that, but I would much prefer to let any java.lang.Error
s propogate upward in their natural fashion, as if I hadn't caught them at all.
Suggestions?
EDIT: It was asked "Why do I want to do this?". I think that's a good question which I will clarify: This is a framework for use in my company. It depends on other frameworks contained in jars, that the system admin might have forgotten to include. In that case there is a NoClassDefFoundError in certain places in the code. But only the user sees this Error in the browser, it is not found in the server logs. I want to log it so the system admin can know that this Error has occurred, as he will have instructions for dealing with it.