Added MustacheContextException

Solving need to distinguish context errors from environment errors.
  The exception has fields for the offending key and line number. This
  is a first step towards internationalization of messages.
This commit is contained in:
pmenhart
2013-03-05 23:33:48 -05:00
parent f3afcda74f
commit c61650734d
4 changed files with 40 additions and 13 deletions
@@ -134,9 +134,9 @@ public class Template
Object data = getValue(ctx, comps[0].intern(), line, missingIsNull);
for (int ii = 1; ii < comps.length; ii++) {
if (data == NO_FETCHER_FOUND) {
if (!missingIsNull) throw new MustacheException(
if (!missingIsNull) throw new MustacheContextException(
"Missing context for compound variable '" + name + "' on line " + line +
". '" + comps[ii - 1] + "' was not found.");
". '" + comps[ii - 1] + "' was not found.", name, line);
return null;
} else if (data == null) {
return null;
@@ -231,8 +231,8 @@ public class Template
_fcache.put(key, fetcher);
return value;
} catch (Exception e) {
throw new MustacheException(
"Failure fetching variable '" + name + "' on line " + line, e);
throw new MustacheContextException(
"Failure fetching variable '" + name + "' on line " + line, name, line, e);
}
}
@@ -240,8 +240,8 @@ public class Template
{
if (value == NO_FETCHER_FOUND) {
if (missingIsNull) return null;
throw new MustacheException(
"No method or field with name '" + name + "' on line " + line);
throw new MustacheContextException(
"No method or field with name '" + name + "' on line " + line, name, line);
} else {
return value;
}