// add catch exception variable.
JLocal catchVar = createLocalThrowable(info, "$caught_ex");
JBlock catchBlock = new JBlock(info);
catchBlock.addStmt(createAssignment(info, javaLangThrowable, exceptionVar, catchVar));
catchBlock.addStmt(new JThrowStatement(info, new JLocalRef(info, exceptionVar)));
catchClauses.add(new JTryStatement.CatchClause(clauseTypes, new JLocalRef(info, catchVar),
catchBlock));
// create finally block
JBlock finallyBlock = new JBlock(info);
for (int i = x.resources.length - 1; i >= 0; i--) {
finallyBlock.addStmt(createCloseBlockFor(info,
resourceVariables.get(i), exceptionVar));
}
// if (exception != null) throw exception
JExpression exceptionNotNull = new JBinaryOperation(info, JPrimitiveType.BOOLEAN,
JBinaryOperator.NEQ, new JLocalRef(info, exceptionVar), JNullLiteral.INSTANCE);
finallyBlock.addStmt(new JIfStatement(info, exceptionNotNull,
new JThrowStatement(info, new JLocalRef(info, exceptionVar)), null));
// Stitch all together into a inner try block
innerBlock.addStmt(new JTryStatement(info, tryBlock, catchClauses,
finallyBlock));
return innerBlock;