import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import static org.objectweb.asm.Opcodes.*;

public class ExceptionTest {

	public static void main(String[] args) throws Throwable {
		var cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
		cw.visit(V17, ACC_PUBLIC, "Test", null, "java/lang/Object", null);
		var mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "run", "()V", null, null);
		mv.visitCode();
		var start = new Label();
		var handler = new Label();
		var end = new Label();
		mv.visitInsn(ACONST_NULL);
		mv.visitLabel(start);
		mv.visitInsn(MONITORENTER);
		mv.visitInsn(ACONST_NULL);
		mv.visitLabel(handler);
		mv.visitInsn(DUP);
		mv.visitInsn(MONITORENTER);
		mv.visitInsn(ATHROW);
		mv.visitLabel(end);
		mv.visitTryCatchBlock(start, end, handler, null);
		mv.visitMaxs(-1, -1);
		mv.visitEnd();
		cw.visitEnd();
		var lookup = MethodHandles.lookup().defineHiddenClass(cw.toByteArray(), true);
		lookup.findStatic(lookup.lookupClass(), "run", MethodType.methodType(void.class)).invokeExact();
	}
}

