Report error when variable or function is not found

This commit is contained in:
2019-12-02 02:11:14 +01:00
parent a49655ed1d
commit d4dad30002
2 changed files with 13 additions and 5 deletions

View File

@@ -17,11 +17,12 @@ namespace VAR.ExpressionEvaluator
public object Eval(IEvaluationContext evaluationContext) public object Eval(IEvaluationContext evaluationContext)
{ {
object[] paramValues = _paramNodes.Select(p => p.Eval(evaluationContext)).ToArray(); object[] paramValues = _paramNodes.Select(p => p.Eval(evaluationContext)).ToArray();
Func<object[], object> func = evaluationContext.GetFunction(_name); Func<object[], object> func = evaluationContext.GetFunction(_name);
if (func == null)
{
throw new Exception(string.Format("Function {0} not found", _name));
}
object result = func(paramValues); object result = func(paramValues);
return result; return result;
} }
} }

View File

@@ -1,4 +1,6 @@
namespace VAR.ExpressionEvaluator using System;
namespace VAR.ExpressionEvaluator
{ {
public class ExpressionVariableNode : IExpressionNode public class ExpressionVariableNode : IExpressionNode
{ {
@@ -11,7 +13,12 @@
public object Eval(IEvaluationContext evaluationContext) public object Eval(IEvaluationContext evaluationContext)
{ {
return evaluationContext.GetVariable(_name); object value = evaluationContext.GetVariable(_name);
if (value == null)
{
throw new Exception(string.Format("Variable {0} not found", _name));
}
return value;
} }
} }
} }