javajava-bytecode-asmtype-annotation

What ASM Visitor Method gets called for type annotation on catch


I have the following code snippet, which I analyze with ASM

   try{
    } catch (@TypeAnno7 RuntimeException re){

    }

I can't find the right method that gets called for the Annotation. I thought MethodVisitor.visitTryCatchAnnotation would do the trick, but it doesn't get called.

So: what is the correct method used? And for what kind of code does the method mentioned get called?


Solution

  • The Java compiler does not generate any bytecode for a try/catch unless the try body contains some code (otherwise, the catch block could never actually run, so it's a form of dead code elimination), which you can verify using javac -p. Add some code to the try body, and then the visitTryCatchAnnotation should be called.