From 8c1965d3eb1879832c7fb3feeb34f4d88ef2ce9c Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Wed, 9 May 2018 18:56:55 +0200 Subject: [PATCH] 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. --- prism/src/prism/PrismLangException.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/prism/src/prism/PrismLangException.java b/prism/src/prism/PrismLangException.java index 5fb8d6b7..c095710d 100644 --- a/prism/src/prism/PrismLangException.java +++ b/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 + "\")"; }