Skip to content

Commit 9c05420

Browse files
committed
(#260) Docs: document the exception thrown
1 parent 4a524f1 commit 9c05420

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ For a more detailed sample, check out the [example project][example]. It shows t
2828
The following example demonstrates usage of `TexFormula` API to render the image into a PNG file using the `RenderToPng` extension method:
2929

3030
```csharp
31+
using System;
3132
using System.IO;
3233
using WpfMath;
3334

@@ -40,15 +41,24 @@ namespace ConsoleApplication2
4041
const string latex = @"\frac{2+2}{2}";
4142
const string fileName = @"T:\Temp\formula.png";
4243

43-
var parser = new TexFormulaParser();
44-
var formula = parser.Parse(latex);
45-
var pngBytes = formula.RenderToPng(20.0, 0.0, 0.0, "Arial");
46-
File.WriteAllBytes(fileName, pngBytes);
44+
try
45+
{
46+
var parser = new TexFormulaParser();
47+
var formula = parser.Parse(latex);
48+
var pngBytes = formula.RenderToPng(20.0, 0.0, 0.0, "Arial");
49+
File.WriteAllBytes(fileName, pngBytes);
50+
}
51+
catch (TexException e)
52+
{
53+
Console.Error.WriteLine("Error when parsing formula: " + e.Message);
54+
}
4755
}
4856
}
4957
}
5058
```
5159

60+
Note that `WpfMath.TexFormulaParser::Parse` may throw a `WpfMath.TexException` if it was unable to parse a formula.
61+
5262
If you need any additional control over the image format, consider using the extension methods from the `WpfTeXFormulaExtensions` class:
5363

5464
```csharp

0 commit comments

Comments
 (0)