Catch all exception handler
Roberto Andrioli <[email protected]> Mon, 1 May 2017 00:16:48 -0300
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CAKJVBvDyMSCQaG=-jgADQsKZMVjr414tu_-dDz9cUWrJ+yEoGA@mail.gmail.com> |
Hello all,
I'm trying to add a catch-all exception handler using ASM core API. My idea
is simply catch all RuntimeExceptions and re-throw. Something like:
```
try {
original_code;
} catch (RuntimeException e) {
throw e;
}
```
One may argue why? The answer is simple. My instrumentation process is
adding code just before xRETURN and ATHROW. This workaround is to deal with
implicit exceptions.
I already implemented a 'working' POC that can be found here:
https://github.com/saeg/ba-dua/commit/5ec4f340158f8c062e8fb94bbd1b999dcfbf85b9
But in this commit I found a few issues. The main ones regarding
unconformity with ASM core API and method call order. Note that I'm calling
visitTryCatchBlock(...) after visit the labels.
I can't simply call visitTryCatchBlock(...) before visitLabel(start) in
visitCode() method. This will register a new handler at the beginning of
the exception table which precedence over all other try-catch blocks.
So my solution came in the following commit:
https://github.com/saeg/ba-dua/commit/4cec4cab0fc1c8ca9b49db28d63b4764fe671bc6
The code tries to add the new try-catch block after all existing ones.
There other comments in the git commit message describing the issues.
I suppose this is a very common transformation used by ASM clients, so I
ask you to feedback. Is this code right? or it's buggy? There others better
way to achieve this?
I appreciate any feedback.
Roberto
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws