|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ExecutionError.java | 25% | 40% | 33.3% | 35.3% |
|
||||||||||||||
| 1 | /* | |
| 2 | * DynamicJava - Copyright (C) 1999-2001 | |
| 3 | * | |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
| 5 | * copy of this software and associated documentation files | |
| 6 | * (the "Software"), to deal in the Software without restriction, including | |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, | |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to permit | |
| 9 | * persons to whom the Software is furnished to do so, subject to the | |
| 10 | * following conditions: | |
| 11 | * The above copyright notice and this permission notice shall be included | |
| 12 | * in all copies or substantial portions of the Software. | |
| 13 | * | |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
| 17 | * IN NO EVENT SHALL DYADE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
| 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
| 20 | * DEALINGS IN THE SOFTWARE. | |
| 21 | * | |
| 22 | * Except as contained in this notice, the name of Dyade shall not be | |
| 23 | * used in advertising or otherwise to promote the sale, use or other | |
| 24 | * dealings in this Software without prior written authorization from | |
| 25 | * Dyade. | |
| 26 | * | |
| 27 | */ | |
| 28 | ||
| 29 | package koala.dynamicjava.interpreter.error; | |
| 30 | ||
| 31 | import java.io.*; | |
| 32 | import koala.dynamicjava.interpreter.*; | |
| 33 | import koala.dynamicjava.tree.*; | |
| 34 | import koala.dynamicjava.util.*; | |
| 35 | ||
| 36 | /** | |
| 37 | * This error is thrown when an unexpected error append while | |
| 38 | * interpreting a statement | |
| 39 | * | |
| 40 | * @author Stephane Hillion | |
| 41 | * @version 1.0 - 1999/04/30 | |
| 42 | */ | |
| 43 | ||
| 44 | public class ExecutionError extends Error { | |
| 45 | ||
| 46 | protected Throwable thrown; | |
| 47 | ||
| 48 | /** | |
| 49 | * The resource bundle name | |
| 50 | */ | |
| 51 | private final static String BUNDLE | |
| 52 | = "koala.dynamicjava.interpreter.resources.messages"; | |
| 53 | ||
| 54 | public final static String SHOW_CAUSE_PROPERTY | |
| 55 | = "koala.dynamicjava.interpreter.showCause"; | |
| 56 | ||
| 57 | public final static String SHOW_TRACE_PROPERTY | |
| 58 | = "koala.dynamicjava.interpreter.showTrace"; | |
| 59 | ||
| 60 | /** | |
| 61 | * The message reader | |
| 62 | */ | |
| 63 | private final static LocalizedMessageReader reader | |
| 64 | = new LocalizedMessageReader(BUNDLE); | |
| 65 | ||
| 66 | /** | |
| 67 | * The syntax tree node where the error occurs | |
| 68 | * @serial | |
| 69 | */ | |
| 70 | private Node node; | |
| 71 | ||
| 72 | /** | |
| 73 | * The raw message | |
| 74 | */ | |
| 75 | private String rawMessage; | |
| 76 | ||
| 77 | /** | |
| 78 | * Constructs an <code>ExecutionError</code> with the specified | |
| 79 | * detail message, filename, line and column. | |
| 80 | * @param s the detail message (a key in a resource file). | |
| 81 | * @param n the syntax tree node where the error occurs | |
| 82 | */ | |
| 83 | 47 | public ExecutionError(String s, Node n) { |
| 84 | 47 | rawMessage = s; |
| 85 | 47 | node = n; |
| 86 | 47 | getMessage(); // ensure that s is valid while we have a useful stack trace |
| 87 | 47 | NodeProperties.setError(n, this); |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Returns the syntax tree node where the error occurs | |
| 92 | */ | |
| 93 | 0 | public Node getNode() { |
| 94 | 0 | return node; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Overridden to delegate to printStackTrace(PrintStream) to print nested | |
| 99 | * exception information. | |
| 100 | * @see #printStackTrace(PrintStream) | |
| 101 | */ | |
| 102 | 0 | public void printStackTrace() { |
| 103 | 0 | this.printStackTrace(System.err); |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Overridden to delegate to printStackTrace(PrintWriter) to print nested | |
| 108 | * exception information. | |
| 109 | * @see #printStackTrace(PrintWriter) | |
| 110 | */ | |
| 111 | 0 | public void printStackTrace(PrintStream s) { |
| 112 | 0 | this.printStackTrace(new PrintWriter(s, true)); |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Handles all calls to printStackTrace(), printing | |
| 117 | * the stack trace of the current exception, and also that of its cause. | |
| 118 | */ | |
| 119 | 0 | public void printStackTrace(PrintWriter w) { |
| 120 | 0 | String trace = System.getProperty(SHOW_TRACE_PROPERTY); |
| 121 | 0 | if (trace != null && !new Boolean(trace).booleanValue()) { |
| 122 | 0 | w.println(this); |
| 123 | } else { | |
| 124 | 0 | super.printStackTrace(w); |
| 125 | 0 | String cause = System.getProperty(SHOW_CAUSE_PROPERTY); |
| 126 | 0 | if (cause == null || new Boolean(cause).booleanValue()) { |
| 127 | 0 | if (thrown != null) { |
| 128 | 0 | w.println("Caused by: "); |
| 129 | 0 | thrown.printStackTrace(w); |
| 130 | } | |
| 131 | } | |
| 132 | } | |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Returns the error message string of this exception | |
| 137 | */ | |
| 138 | 141 | public String getMessage() { |
| 139 | 141 | String [] args = new String[0]; |
| 140 | 123 | if (node != null && NodeProperties.hasErrorStrings(node)) { args = NodeProperties.getErrorStrings(node); } |
| 141 | 141 | return reader.getMessage(rawMessage, args); |
| 142 | } | |
| 143 | } |
|
||||||||||