Re: How to wrap a function with a try finally block
Eugene Kuleshov <[email protected]>
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
Look at the "Insert Code before Method Exit" section in my AOSD'07 paper linked from the project home page. regards, Eugene On Thu, Mar 25, 2010 at 9:49 AM, <[email protected]> wrote: > I tried to write a tool to add a static method to every function and guarantee > it is called before the method return, i wrote something in the MethodAdaptor > like this: > public void visitInsn(int opcode) > { > if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == > Opcodes.ATHROW) { > mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, methodName, > "()V"); > } > > mv.visitInsn(opcode); > } > > It does not work when the method calls some other method and that guy throws a > RuntimeException, then i tried to use try finally to wrap the whole method body > like this: > transfer > private void method1() > { > code.... > ... > } > to: > private void method1() > { > try { > code.... > ... > } finally { > StaticClass.method(); > } > } > > I wrote a small class and checked the binary code with both javap and > ASMifierClassVisitor, then i realized that i have to figure out every posible > branche that may jump into the finally block and do something with the > exception table. > > I have read the guild and have not got anything helpful. It's too hard or i > just can't do this? > > Thanks for your patience.
message-footer.txt
(text/plain, 238 B)
-- 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