Some test text!

menu
search
Error Handlingkeyboard_arrow_down

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 PDFTron 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, PDFTron 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:

string errText = "NONE";
try
{
    pdftron.PDF.PDFDoc doc = new pdftron.PDF.PDFDoc("not_valid");
}
catch (Exception ex)
{
    pdftron.Common.PDFNetException pdfNetEx = new pdftron.Common.PDFNetException(ex.HResult);
    if (pdfNetEx.IsPDFNetException)
    {
      errText = string.Format("Exeption at line {0} in file {1}", pdfNetEx.LineNumber, pdfNetEx.FileName);
      errText += Environment.NewLine;
      errText += string.Format("Message: {0}", pdfNetEx.Message);
    }
    else
    {
      errText = ex.ToString();
    }
}
MessageDialog errorDialog = new MessageDialog(errText);
await 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 PDFTron 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.

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close