1 33 34 35 package bsh; 36 37 47 public class EvalError extends Exception 48 { 49 SimpleNode node; 50 51 String message; 53 54 CallStack callstack; 55 56 public EvalError( String s, SimpleNode node, CallStack callstack ) { 57 setMessage(s); 58 this.node = node; 59 if ( callstack != null ) 61 this.callstack = callstack.copy(); 62 } 63 64 67 public String toString() 68 { 69 String trace; 70 if ( node != null ) 71 trace = " : at Line: "+ node.getLineNumber() 72 + " : in file: "+ node.getSourceFile() 73 + " : "+node.getText(); 74 else 75 trace = ": <at unknown location>"; 77 78 if ( callstack != null ) 79 trace = trace +"\n" + getScriptStackTrace(); 80 81 return getMessage() + trace; 82 } 83 84 87 public void reThrow( String msg ) 88 throws EvalError 89 { 90 prependMessage( msg ); 91 throw this; 92 } 93 94 98 SimpleNode getNode() { 99 return node; 100 } 101 102 void setNode( SimpleNode node ) { 103 this.node = node; 104 } 105 106 public String getErrorText() { 107 if ( node != null ) 108 return node.getText() ; 109 else 110 return "<unknown error>"; 111 } 112 113 public int getErrorLineNumber() { 114 if ( node != null ) 115 return node.getLineNumber() ; 116 else 117 return -1; 118 } 119 120 public String getErrorSourceFile() { 121 if ( node != null ) 122 return node.getSourceFile() ; 123 else 124 return "<unknown file>"; 125 } 126 127 public String getScriptStackTrace() 128 { 129 if ( callstack == null ) 130 return "<Unknown>"; 131 132 String trace = ""; 133 CallStack stack = callstack.copy(); 134 while ( stack.depth() > 0 ) 135 { 136 NameSpace ns = stack.pop(); 137 SimpleNode node = ns.getNode(); 138 if ( ns.isMethod ) 139 { 140 trace = trace + "\nCalled from method: " + ns.getName(); 141 if ( node != null ) 142 trace += " : at Line: "+ node.getLineNumber() 143 + " : in file: "+ node.getSourceFile() 144 + " : "+node.getText(); 145 } 146 } 147 148 return trace; 149 } 150 151 154 public String getMessage() { return message; } 155 156 public void setMessage( String s ) { message = s; } 157 158 161 protected void prependMessage( String s ) 162 { 163 if ( s == null ) 164 return; 165 166 if ( message == null ) 167 message = s; 168 else 169 message = s + " : "+ message; 170 } 171 172 } 173 174 | Popular Tags |