| 24 | import lombok.EqualsAndHashCode; |
| 25 | |
| 26 | @EqualsAndHashCode(callSuper=false) |
| 27 | public class AstException extends RuntimeException { |
| 28 | private final Node problemNode; |
| 29 | private final String message; |
| 30 | |
| 31 | public AstException(Node problemNode, String message) { |
| 32 | super(message); |
| 33 | this.message = message; |
| 34 | this.problemNode = problemNode; |
| 35 | } |
| 36 | |
| 37 | @Override public String toString() { |
| 38 | if (problemNode == null && getMessage() == null) return "AstException (unknown cause)"; |
| 39 | if (problemNode == null) return "AstException: " + getMessage(); |
| 40 | String nodeDescription = problemNode == null ? "(null)" : (problemNode.getClass().getName() + "(toString failed)"); |
| 41 | try { |
| 42 | nodeDescription = problemNode.toString(); |
| 43 | } catch (Throwable ignore) { |
| 44 | //throwing exceptions in toString() is bad. |
| 45 | } |
| 46 | if (getMessage() == null) return "AstException at " + nodeDescription; |
| 47 | return String.format("AstException: %s (at %s)", getMessage(), nodeDescription); |
| 48 | } |
| 49 | } |
nothing calls this directly
no outgoing calls
no test coverage detected