Re: injecting code to exception handler

Eliot Moss <[email protected]> Tue, 22 Apr 2014 09:51:44 -0400
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
On 4/17/2014 12:01 AM, Bing Ran wrote:

> Wondering how I can inject some code in the beginning of all the catch blocks. I don't seem to be
> able to find the proper method to override in a MethodVisitor.

I don't recall what responses have been posed (maybe even by me),
but here are some quick thoughts:

1) You'll need to process the try-catch block information and
remember the labels of the starts of handlers -- perhaps in a
HashSet.

2) As you encounter Label's in the code (visitLabel) check to
see if the Label is one in your HashSet, which implies it is
at the start of a handler.  *After* doing a super.visitLabel
call, do your calls to insert code.

I have often found it to be the case that interesting transformations
require a certain amount of tracking/analysis of the stream of
instructions and other related info, and selective transformation
based on context.

Regards -- Eliot Moss
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