final CatchClause catchClause = new CatchClause(
new BlockStatement(
new ExpressionStatement(
new AssignmentExpression(
new IdentifierExpressionBackReference("savedException").toExpression(),
new NamedNode("caughtException", new IdentifierExpression(Expression.MYSTERY_OFFSET, Pattern.ANY_STRING)).toExpression()
)
),
new ThrowStatement(new IdentifierExpressionBackReference("caughtException").toExpression())
)
);
catchClause.setVariableName(Pattern.ANY_STRING);
catchClause.getExceptionTypes().add(new SimpleType("Throwable"));
tryPattern.getCatchClauses().add(catchClause);
final TryCatchStatement disposeTry = new TryCatchStatement(Expression.MYSTERY_OFFSET);
disposeTry.setTryBlock(
new BlockStatement(
new ExpressionStatement(
new IdentifierExpressionBackReference("resource").toExpression().invoke("close")
)
)
);
final CatchClause disposeCatch = new CatchClause(
new BlockStatement(
new ExpressionStatement(
new IdentifierExpressionBackReference("savedException").toExpression().invoke(
"addSuppressed",
new NamedNode("caughtOnClose", new IdentifierExpression(Expression.MYSTERY_OFFSET, Pattern.ANY_STRING)).toExpression()
)
)
)
);