Revision 44098 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultInterpreter.java

View differences:

DefaultInterpreter.java
15 15
import org.gvsig.expressionevaluator.Code.Caller;
16 16
import org.gvsig.expressionevaluator.Code.Caller.Arguments;
17 17
import org.gvsig.expressionevaluator.Code.Method;
18
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
18 19
import org.gvsig.expressionevaluator.Function;
19
import org.gvsig.expressionevaluator.Optimizer;
20 20
import org.gvsig.expressionevaluator.impl.function.operator.BinaryOperator;
21 21
import org.gvsig.expressionevaluator.impl.function.obj.InvokeMethodFunction;
22 22
import org.gvsig.expressionevaluator.impl.function.operator.UnaryOperator;
......
126 126
    public Object run(Code code) {
127 127
        try {
128 128
            return this.runCode(code);
129
        } catch (Exception ex) {
130
            throw new RuntimeException(ex);
129
        } catch(RuntimeException ex) {
130
            throw ex;
131
        } catch(Exception ex) {
132
            throw new ExpressionRuntimeException(code, "", ex);
131 133
        }
132 134
    }
133 135

  
......
161 163
        case Code.IDENTIFIER:
162 164
            String name = ((Identifier) code).name();
163 165
            if( !this.getSymbolTable().exists(name) ) {
164
                throw new RuntimeException("Variable '" + name + "' not found.");
166
                throw new ExpressionRuntimeException(
167
                        code, 
168
                        I18N.Undefined_variable_XIdentifierX(name),
169
                        I18N.Use_single_quotes_to_enter_literal_strings()
170
                );
165 171
            }
166 172
            value = this.getSymbolTable().value(name);
167 173
            break;
......
183 189
            if( function == null ) {
184 190
                function = this.getSymbolTable().function(caller.name());
185 191
                if( function == null ) {
186
                    throw new RuntimeException("Function '" + caller.name() + "' not found.");
192
                    throw new ExpressionRuntimeException(code, I18N.Undefined_function_XIdentifierX(caller.name()));
187 193
                }
188 194
                caller.function(function);
189 195
            }
......
192 198
                switch( caller.type() ) {
193 199
                case Caller.UNARY_OPERATOR:
194 200
                    if( args == null || args.count() != 1 ) {
195
                        throw new RuntimeException("Number of argument mistmatch in operator '"+function.name()+"', expected 1 got " + args.count() + ".");
201
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_operator_XIdentifierX_expected_1_got_XargcX(function.name(),args==null?0:args.count()));
196 202
                    }
197 203
                    value = ((UnaryOperator) function).call(this, runCode(args.get(0)));
198 204
                    break;
199 205

  
200 206
                case Caller.BINARY_OPERATOR:
201 207
                    if( args == null || args.count() != 2 ) {
202
                        throw new RuntimeException("Number of argument mistmatch in operator '"+function.name()+"', expected 2 got " + args.count() + ".");
208
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_operator_XIdentifierX_expected_2_got_XargcX(function.name(),args==null?0:args.count()));
203 209
                    }
204 210
                    value = ((BinaryOperator) function).call(this, runCode(args.get(0)), runCode(args.get(1)));
205 211
                    break;
......
207 213
                case Caller.FUNCTION:
208 214
                    int argc = (args == null) ? 0 : args.count();
209 215
                    if( !function.argc().contains(argc) ) {
210
                        throw new RuntimeException("Number of argument mistmatch in function '"+function.name()+"', expected " + function.argc() + " got " + argc + ".");
216
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_function_XIdentifierX_expected_XexpectedX_got_XfoundX(function.name(),function.argc(),argc));
211 217
                    }
212 218
                    if( function.useArgumentsInsteadObjects() ) {
213 219
                        value = function.call(this, args);
......
222 228
                        value = function.call(this, argvalues);
223 229
                    }
224 230
                }
231
            } catch (RuntimeException ex) {
232
                throw ex;
225 233
            } catch (Exception ex) {
226 234
                String argsstr = "???";
227 235
                try {
......
229 237
                } catch(Exception ex2) {
230 238
                    // Ignore.
231 239
                }
232
                throw new RuntimeException("Problems calling function '"+function.name()+"' with args ("+argsstr+").", ex);
240
                throw new ExpressionRuntimeException(code, I18N.Problems_calling_function_XIdentifierX_with_args_XargsX(function.name(),argsstr));
233 241
            }
234 242
            break;
235 243
            

Also available in: Unified diff