Re: Catch all exception handler
Roberto Andrioli <[email protected]> Mon, 1 May 2017 13:10:52 -0300
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CAKJVBvCuqZ5tMs2U0ZY6GsvGFiDuHuiLqQXqhG=-wJZZddFscw@mail.gmail.com> |
Remi, I known that. But I need the try-catch block to avoid the "abruptly" method termination due to exceptions. After a good sleep I realized that I should not simply catch all RuntimeExceptions but catch all Exceptions (or even all Throwable errors). This workaround is not to deal with implicit exceptions as I said, but to deal with unhandled exceptions (that may or not be implicit). Remember that my instrumentation process will add code for each method before all ATHROW/xRETURN instructions. Without the try-catch block the method can exit without call my added instrumentation. On Mon, May 1, 2017 at 7:18 AM, Remi Forax <[email protected]> wrote: > 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/5ec4f340158f8c062e8fb94bbd1b99 > 9dcfbf85b9 > > 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