Browse Source

PrismLangException.getMessage(): Make robust if ASTElement printing fails

If there is a problem in ASTElement.toString for the AST element
that is optionally attached to the exception, we catch the exception
and return the error message without it.
master
Joachim Klein 8 years ago
parent
commit
8c1965d3eb
  1. 10
      prism/src/prism/PrismLangException.java

10
prism/src/prism/PrismLangException.java

@ -64,8 +64,14 @@ public class PrismLangException extends PrismException
{
String msg = super.getMessage();
if (e == null) return msg;
String s = e.toString();
if (s.length() < MAX_ERR_STR) {
String s = null;
try {
s = e.toString();
} catch (Exception ex) {
// in case there is a problem converting the AST element to a string
// we ignore it
}
if (s != null && s.length() < MAX_ERR_STR) {
if (e.hasPosition()) msg += " (\"" + s + "\", " + e.getBeginString() +")";
else msg += " (\"" + s + "\")";
}

Loading…
Cancel
Save