use of lucee.transformer.bytecode.statement.TryCatchFinally in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method tryStatement.
/**
* Liest eine try Block ein
* <br />
* EBNF:<br />
* <code>;</code>
* @return Try Block
* @throws TemplateException
*/
private final TryCatchFinally tryStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("try", '{') && !data.srcCode.forwardIfCurrent("try ") && !data.srcCode.forwardIfCurrent("try", '/'))
return null;
data.srcCode.previous();
Body body = new BodyBase(data.factory);
TryCatchFinally tryCatchFinally = new TryCatchFinally(data.factory, body, data.srcCode.getPosition(), null);
statement(data, body, CTX_TRY);
comments(data);
// catches
short catchCount = 0;
while (data.srcCode.forwardIfCurrent("catch", '(')) {
catchCount++;
comments(data);
// type
int pos = data.srcCode.getPos();
Position line = data.srcCode.getPosition();
Expression name = null, type = null;
StringBuffer sbType = new StringBuffer();
String id;
while (true) {
id = identifier(data, false);
if (id == null)
break;
sbType.append(id);
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent('.'))
break;
sbType.append('.');
data.srcCode.removeSpace();
}
if (sbType.length() == 0) {
type = string(data);
if (type == null)
throw new TemplateException(data.srcCode, "a catch statement must begin with the throwing type (query, application ...).");
} else {
type = data.factory.createLitString(sbType.toString());
}
// name = expression();
comments(data);
// name
if (!data.srcCode.isCurrent(')')) {
name = expression(data);
} else {
data.srcCode.setPos(pos);
name = expression(data);
type = data.factory.createLitString("any");
}
comments(data);
Body b = new BodyBase(data.factory);
try {
tryCatchFinally.addCatch(type, name, b, line);
} catch (TransformerException e) {
throw new TemplateException(data.srcCode, e.getMessage());
}
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid catch statement, missing closing )");
statement(data, b, CTX_CATCH);
comments(data);
}
// finally
if (finallyStatement(data, tryCatchFinally)) {
comments(data);
} else if (catchCount == 0)
throw new TemplateException(data.srcCode, "a try statement must have at least one catch statement");
// if(body.isEmpty()) return null;
tryCatchFinally.setEnd(data.srcCode.getPosition());
return tryCatchFinally;
}
use of lucee.transformer.bytecode.statement.TryCatchFinally in project Lucee by lucee.
the class Retry method getAncestorCatch.
public static Statement getAncestorCatch(TagLib tagLib, Statement stat) {
String name = tagLib.getNameSpaceAndSeparator() + "catch";
Tag tag;
Statement parent = stat;
while (true) {
parent = parent.getParent();
if (parent == null)
return null;
if (parent instanceof Tag) {
tag = (Tag) parent;
if (tag.getFullname().equalsIgnoreCase(name))
return tag;
} else if (parent instanceof TryCatchFinally)
return parent;
}
}
Aggregations