diff --git a/src/WpfMath.Tests/ParserExceptionTests.fs b/src/WpfMath.Tests/ParserExceptionTests.fs index 36764ba4..5757ac11 100644 --- a/src/WpfMath.Tests/ParserExceptionTests.fs +++ b/src/WpfMath.Tests/ParserExceptionTests.fs @@ -107,3 +107,8 @@ let ``Nonexistent color throws a TexParseException``(text: string): unit = let ``Invalid color numbers throw exceptions``(formula: string, colorModel: string): unit = let ex = assertParseThrows formula Assert.Contains(colorModel, ex.Message) + +[] +let ``Invalid delimiter test``(): unit = + let ex = assertParseThrows @"\left{2+2\right\}" + Assert.Contains(@"A delimiter should start from \, but got 2+2\right\", ex.Message) diff --git a/src/WpfMath/Controls/FormulaControl.xaml.cs b/src/WpfMath/Controls/FormulaControl.xaml.cs index d2dfc4e5..d2f660e6 100644 --- a/src/WpfMath/Controls/FormulaControl.xaml.cs +++ b/src/WpfMath/Controls/FormulaControl.xaml.cs @@ -199,6 +199,11 @@ private static object CoerceFormula(DependencyObject d, object baseValue) control.SetError(e); return ""; } + catch (Exception e) + { + control.SetError(new TexParseException("Parser crash! " + e.Message, e)); + return ""; + } } private static object CoerceScaleValue(DependencyObject d, object baseValue) diff --git a/src/XamlMath.Shared/TexFormulaParser.cs b/src/XamlMath.Shared/TexFormulaParser.cs index 9a088bcd..535a0d46 100644 --- a/src/XamlMath.Shared/TexFormulaParser.cs +++ b/src/XamlMath.Shared/TexFormulaParser.cs @@ -401,7 +401,7 @@ private SymbolAtom ParseDelimiter(SourceSpan value, int start, ref int position) else { if (delimiter[0] != escapeChar) - throw new Exception($"Incorrect parser state: delimiter should start from {escapeChar}: {delimiter}"); + throw new TexParseException($"A delimiter should start from {escapeChar}, but got {delimiter}"); // Here goes the fancy business: for non-alphanumeric commands (e.g. \{, \\ etc.) we need to pass them // through GetDelimeterMapping, but for alphanumeric ones, we don't.