때로는 ASM 프레임 워크를 만지작 거리고 있습니다. 나는 단지 예외를 잡기를 원한다.ASM에서 메소드 서명을 기반으로 예외를 throw 할 수 있습니까?
지금까지 바이트 코드에 try-catch
블록을 삽입하고 예외를 catch 할 수있었습니다.
이것은 내가 지금하고있는 일입니다.
public void visitMaxs(int maxStack, int maxLocals)
{
// visit try block end label
this.visitLabel(lblTryBlockEnd);
// visit normal execution exit block
//this.visitJumpInsn(Opcodes.GOTO, exitBlock);
// visit catch exception block
this.visitLabel(lblCatchExceptionBlockStart);
// store the exception
this.visitVarInsn(Opcodes.ASTORE, 1);
super.visitTypeInsn(Opcodes.NEW, "java/lang/Exception");
super.visitInsn(Opcodes.DUP);
// load the exception
this.visitVarInsn(Opcodes.ALOAD, 1);
// Initializing the exception object with the throwable cause
super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Exception", "<init>", "(Ljava/lang/Throwable;)V");
// calling jensor method to write
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"test/ExceptionHandleTest",
"exceptionHandler",
"(Ljava/lang/Exception;)V");
// call printStackTrace()
this.visitInsn(Opcodes.ATHROW);
// exit from this dynamic block
this.visitLabel(exitBlock);
super.visitMaxs(maxStack+2, maxLocals);
}
`
지금, 내가 대신 나는 그것이 MethodVisitor
방법 서명의 exception
매개 변수와 일치하는 경우에만 던져하려면, (지금 athrow
때마다 일을 오전으로) 모든 잡힌 예외를 throw하지 않습니다.
시도했지만 Falling off the end of the code
클래스 확인 오류가 발생했습니다.
ASM을 사용할 수 있습니까?
미리 감사드립니다.
예, ASMifier는 훌륭합니다. – omainegra