use of org.apache.calcite.linq4j.tree.CatchBlock in project ignite-3 by apache.
the class RexToLixTranslator method handleMethodCheckedExceptions.
/**
* Handle checked Exceptions declared in Method. In such case, method call should be wrapped in a try...catch block.
* " final Type method_call; try { method_call = callExpr } catch (Exception e) { throw new RuntimeException(e); } "
*/
Expression handleMethodCheckedExceptions(Expression callExpr) {
// Try statement
ParameterExpression methodCall = Expressions.parameter(callExpr.getType(), list.newName("method_call"));
list.add(Expressions.declare(Modifier.FINAL, methodCall, null));
Statement st = Expressions.statement(Expressions.assign(methodCall, callExpr));
// Catch Block, wrap checked exception in unchecked exception
ParameterExpression e = Expressions.parameter(0, Exception.class, "e");
Expression uncheckedException = Expressions.new_(RuntimeException.class, e);
CatchBlock cb = Expressions.catch_(e, Expressions.throw_(uncheckedException));
list.add(Expressions.tryCatch(st, cb));
return methodCall;
}
use of org.apache.calcite.linq4j.tree.CatchBlock in project calcite by apache.
the class InlinerTest method testInlineInTryCatchStatement.
@Test
void testInlineInTryCatchStatement() {
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t = Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(Modifier.FINAL, t, ONE));
final ParameterExpression u = Expressions.parameter(int.class, "u");
builder.add(Expressions.declare(Modifier.FINAL, u, null));
Statement st = Expressions.statement(Expressions.assign(u, Expressions.makeBinary(ExpressionType.Add, t, TWO)));
ParameterExpression e = Expressions.parameter(0, Exception.class, "e");
CatchBlock cb = Expressions.catch_(e, Expressions.throw_(e));
builder.add(Expressions.tryCatch(st, cb));
builder.add(Expressions.return_(null, u));
assertEquals("{\n" + " final int u;\n" + " try {\n" + " u = 1 + 2;\n" + " } catch (Exception e) {\n" + " throw e;\n" + " }\n" + " return u;\n" + "}\n", builder.toBlock().toString());
}
use of org.apache.calcite.linq4j.tree.CatchBlock in project calcite by apache.
the class RexToLixTranslator method handleMethodCheckedExceptions.
/**
* Handle checked Exceptions declared in Method. In such case,
* method call should be wrapped in a try...catch block.
* "
* final Type method_call;
* try {
* method_call = callExpr
* } catch (Exception e) {
* throw new RuntimeException(e);
* }
* "
*/
Expression handleMethodCheckedExceptions(Expression callExpr) {
// Try statement
ParameterExpression methodCall = Expressions.parameter(callExpr.getType(), list.newName("method_call"));
list.add(Expressions.declare(Modifier.FINAL, methodCall, null));
Statement st = Expressions.statement(Expressions.assign(methodCall, callExpr));
// Catch Block, wrap checked exception in unchecked exception
ParameterExpression e = Expressions.parameter(0, Exception.class, "e");
Expression uncheckedException = Expressions.new_(RuntimeException.class, e);
CatchBlock cb = Expressions.catch_(e, Expressions.throw_(uncheckedException));
list.add(Expressions.tryCatch(st, cb));
return methodCall;
}
Aggregations