Error handling

It is possible to get more useful error messages when PDFNet throws exceptions.

Due to limitations of the COM API boundary, only System.Exception could be passed from the Apryse SDK to the consuming code. This limited the errors to those that were already defined and prevented custom information to be attached.

To overcome this, Apryse SDK for UWP has a class: pdfnet.Common.PDFNetException that can be created with an HResult from a System.Exception and will be able to display the information relevant to the error that caused the Exception.

The following code snippet shows an example in how to use the PDFNetException class:

C#

1string errText = "NONE";
2try
3{
4 pdftron.PDF.PDFDoc doc = new pdftron.PDF.PDFDoc("not_valid");
5}
6catch (Exception ex)
7{
8 pdftron.Common.PDFNetException pdfNetEx = new pdftron.Common.PDFNetException(ex.HResult);
9 if (pdfNetEx.IsPDFNetException)
10 {
11 errText = string.Format("Exeption at line {0} in file {1}", pdfNetEx.LineNumber, pdfNetEx.FileName);
12 errText += Environment.NewLine;
13 errText += string.Format("Message: {0}", pdfNetEx.Message);
14 }
15 else
16 {
17 errText = ex.ToString();
18 }
19}
20MessageDialog errorDialog = new MessageDialog(errText);
21await errorDialog.ShowAsync();

This will show what the error message is, and the line and file in which it happened.

This information will be very valuable to us if PDFNet throws an unexpected Exception. If you encounter an Exception while working with the Apryse SDK for UWP, it is a good idea to include the full error from PDFNetException.ToString() with the description of the problem to sent to our support team.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales