Skip to content

Commit 1a6e52e

Browse files
committed
Add a specific Exception when expression is empty
1 parent ad09e44 commit 1a6e52e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,9 @@ protected virtual bool EvaluateString(string expression, Stack<object> stack, re
28482848

28492849
protected virtual object ProcessStack(Stack<object> stack)
28502850
{
2851+
if (stack.Count == 0)
2852+
throw new ExpressionEvaluatorSyntaxErrorException("Empty expression or no token found");
2853+
28512854
List<object> list = stack
28522855
.Select(e => e is ValueTypeNestingTrace valueTypeNestingTrace ? valueTypeNestingTrace.Value : e)
28532856
.Select(e => e is SubExpression subExpression ? Evaluate(subExpression.Expression) : e)
@@ -2964,7 +2967,6 @@ protected virtual object ProcessStack(Stack<object> stack)
29642967

29652968
return stack.Pop();
29662969
}
2967-
29682970
#endregion
29692971

29702972
#region Remove comments

TryWindow/MainWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public MainWindow()
2525
{
2626
InitializeComponent();
2727

28+
new ExpressionEvaluator().Evaluate("");
29+
2830
if (File.Exists(persistCodeFileName))
2931
ScriptTextBox.Text = File.ReadAllText(persistCodeFileName);
3032
if (File.Exists(persistIterationFileName))

0 commit comments

Comments
 (0)