Re: Catch all exception handler

Remi Forax <[email protected]> Mon, 1 May 2017 12:18:43 +0200 (CEST)
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
Roberto, 
the VM has no concept of checked or runtime exception, it's the java compiler that makes a difference. 
So i believe you do not need a try/catch. 

Rémi 

> De: "Roberto Andrioli" <[email protected]>
> À: [email protected]
> Envoyé: Lundi 1 Mai 2017 05:16:48
> Objet: [asm] Catch all exception handler

> 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


-- 
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