本文整理汇总了Java中org.apache.bcel.generic.MethodGen.addExceptionHandler方法的典型用法代码示例。如果您正苦于以下问题:Java MethodGen.addExceptionHandler方法的具体用法?Java MethodGen.addExceptionHandler怎么用?Java MethodGen.addExceptionHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.MethodGen
的用法示例。
在下文中一共展示了MethodGen.addExceptionHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHelperMethodForDotClassCalls
import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
/**
* Creates a method class$(String) which is used
* during SomeClass.class instruction
*
* @param generatedClassName the instance class name
*/
protected void createHelperMethodForDotClassCalls(String generatedClassName) {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool);
InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT));
InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1));
il.append(factory.createNew("java.lang.NoClassDefFoundError"));
il.append(InstructionConstants.DUP);
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException"));
method.setMaxStack();
method.setMaxLocals();
classGen.addMethod(method.getMethod());
il.dispose();
}
示例2: generateMain
import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
void generateMain(ClassGen clg, Method origMain) {
InstructionList il = new InstructionList();
MethodGen new_main = new MethodGen(Constants.ACC_STATIC
| Constants.ACC_PUBLIC, Type.VOID, new Type[] { new ArrayType(
Type.STRING, 1) }, new String[] { "argv" }, "main", clg
.getClassName(), il, clg.getConstantPool());
il.append(ins_f.createNew(cashmereType));
il.append(new DUP());
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "<init>",
Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster",
Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
BranchHandle ifcmp = il.append(new IFEQ(null));
InstructionHandle origMain_handle = il.append(new ALOAD(0));
InstructionHandle try_start = il.append(ins_f.createInvoke(clg
.getClassName(), origMain.getName(), Type.VOID,
new Type[] { new ArrayType(Type.STRING, 1) },
Constants.INVOKESTATIC));
BranchHandle try_end = il.append(new GOTO(null));
InstructionHandle e_handler = il.append(getCashmere(ins_f));
il.append(new SWAP());
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit",
Type.VOID, new Type[] { new ObjectType("java.lang.Throwable")},
Constants.INVOKEVIRTUAL));
BranchHandle gto2 = il.append(new GOTO(null));
InstructionHandle ifeq_target = il.append(getCashmere(ins_f));
ifcmp.setTarget(ifeq_target);
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "client",
Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(getCashmere(ins_f));
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster",
Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(new IFNE(origMain_handle));
InstructionHandle gto_target = il.append(getCashmere(ins_f));
try_end.setTarget(gto_target);
il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit",
Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
InstructionHandle gto2_target = il.append(new RETURN());
gto2.setTarget(gto2_target);
new_main.addExceptionHandler(try_start, try_end, e_handler,
new ObjectType("java.lang.Throwable"));
new_main.setMaxStack();
new_main.setMaxLocals();
new_main.addLocalVariable("argv", new ArrayType(Type.STRING, 1), 0,
origMain_handle, null);
removeLocalTypeTables(new_main);
Method main = new_main.getMethod();
gen_c.addMethod(main);
}