New to Telerik Document ProcessingStart a free 30-day trial

Handling Exceptions

Updated on Jun 3, 2026
Minimum VersionR2 2020

RadPdfProcessing has an exception handling mechanism. It allows you to intercept and handle exceptions when the document is imported or loaded. This functionality introduces the following events:

EventDescription
PdfImportSettings.DocumentUnhandledExceptionFired when an exception occurs during document import. If ReadingMode is AllAtOnce, the entire document is loaded on import and this event covers the full load.
RadFixedDocument.DocumentUnhandledExceptionFired when an exception occurs while loading document pages. Raised when the document is imported with OnDemand ReadingMode and a particular page is loaded after import.
PdfExportSettings.DocumentUnhandledExceptionFired when an exception occurs while exporting document pages. Introduced in Q1 2025.
SkiaImageExportSettings.DocumentUnhandledExceptionFired when an exception occurs while exporting a PDF page. Introduced in Q3 2025. (Available in the .NET Standard version of the libraries.)

When the events are raised, the DocumentUnhandledExceptionEventArgs argument is passed. This argument contains the following properties:

PropertyDescription
ExceptionGets the document exception.
HandledGets or sets whether the exception is handled. The default value is false.

The exception handling mechanism handles exceptions at the very beginning of the import as well. In such a case, the event is raised and an empty document instance is returned. The exception handling mechanism does not handle exceptions while parsing fonts glyph data or parsing images during document rendering in the UI viewers.

Using ImportSettings.DocumentUnhandledException

To use this functionality, handle the PdfImportSettings.DocumentUnhandledException event. The Handled property in the event arguments indicates whether the exception is handled by the code in the event handler or the exception is thrown.

C#
PdfFormatProvider provider = new PdfFormatProvider();
provider.ImportSettings.ReadingMode = ReadingMode.AllAtOnce;
provider.ImportSettings.DocumentUnhandledException += (s, e) =>
{
    Debug.WriteLine("The document is corrupted and cannot be loaded: " + e.Exception.Message);
    e.Handled = true;
};
RadFixedDocument document = provider.Import(File.ReadAllBytes("SampleDoc.pdf"), TimeSpan.FromSeconds(10));

Using RadFixedDocument.DocumentUnhandledException

When you use the OnDemand reading mode, handle the RadFixedDocument.DocumentUnhandledException event. The Handled option in the event arguments indicates whether the exception is handled by the code in the event handler or the exception is thrown.

Example 2: Using the DocumentUnhandledException Event While Loading on Demand

C#
PdfFormatProvider provider = new PdfFormatProvider();
provider.ImportSettings.ReadingMode = ReadingMode.OnDemand;
RadFixedDocument document = provider.Import(File.ReadAllBytes("SampleDoc.pdf"), TimeSpan.FromSeconds(10));
document.DocumentUnhandledException += (s, e) =>
{
    Debug.WriteLine("The document is corrupted and cannot be loaded: " + e.Exception.Message);
    e.Handled = true;
};

Using ExportSettings.DocumentUnhandledException

Starting with Q1 2025, the PdfExportSettings offers the DocumentUnhandledException event that allows you to handle exceptions while exporting a document.

Example 3: Using the DocumentUnhandledException Event While Exporting

C#
PdfFormatProvider provider = new PdfFormatProvider();
PdfExportSettings settings = new PdfExportSettings();
provider.ExportSettings.DocumentUnhandledException += (s, e) =>
{
    Debug.WriteLine("The document is corrupted and cannot be exported: " + e.Exception.Message);
    e.Handled = true;
};

Exceptions

ExceptionDescription
DuplicatedEmbeddedFileNameExceptionRepresents an exception for embedding a file with a duplicated name.
InvalidActionExceptionRepresents an exception for importing an invalid action.
InvalidGraphicOperandsCountExceptionRepresents an exception for importing a graphic operator with an invalid number of operands.
NotSupportedActionExceptionRepresents an exception for an action that is not supported.
NotSupportedCCITTFaxDecodeFilterExceptionRepresents an exception for a scan decoder that is not supported.
NotSupportedCharsetFormatExceptionRepresents an exception for a charset format that is not supported. This exception has a CharsetFormat property that specifies the name of the CharsetFormat.
NotSupportedColorSpaceExceptionRepresents an exception for a color space that is not supported. This exception has a ColorSpace property that specifies the name of the ColorSpace.
NotSupportedCompressionMethodExceptionRepresents an exception for importing a FlateDecode method that is not supported.
NotSupportedEncryptionExceptionRepresents an exception for an encryption that is not supported. This exception has an EncryptionCode property that specifies the code of the encryption.
NotSupportedEncryptionRevisionExceptionRepresents an exception for an encryption revision that is not supported. This exception has a RevisionCode property that specifies the name of the RevisionCode.
NotSupportedFeatureExceptionRepresents an exception for a feature that is not supported.
NotSupportedFilterExceptionRepresents an exception for a filter that is not supported. This exception has a FilterName property that specifies the name of the filter.
NotSupportedFontExceptionRepresents an exception for a font that is not supported. This exception has a FontType property that specifies the type of the font.
NotSupportedFontFamilyExceptionRepresents an exception for a font family that is not supported.
NotSupportedFunctionTypeExceptionRepresents an exception for a function type that is not supported. This exception has a FunctionType property that specifies the name of the FunctionType.
NotSupportedPaintTypeExceptionRepresents an exception for a paint type that is not supported. This exception has a PaintType property that specifies the name of the PaintType.
NotSupportedPredefinedCMapExceptionRepresents an exception for a predefined CMap that is not supported. This exception has a CMapName property that specifies the name of the predefined CMap.
NotSupportedReservedMethodExceptionRepresents an exception for importing a FlateDecode reserved method that is not supported.
NotSupportedScanDecoderExceptionRepresents an exception for a document with a scan decoder that is not supported.
NotSupportedScanEncoderExceptionRepresents an exception for a scan decoder that is not supported.
NotSupportedShadingTypeExceptionRepresents an exception for a shading type that is not supported. This exception has a ShadingType property that specifies the type of the shading.
NotSupportedStreamTypeExceptionRepresents an exception for a stream type that is not supported. A stream is not supported if it does not support read or seek. This exception has SupportSeek and SupportRead properties that specify whether the stream supports them.
NotSupportedXObjectTypeExceptionRepresents an exception for a document with an XObject type that is not supported.
DuplicatedJavaScriptNameExceptionRepresents an exception for JavaScript with a duplicated name.
NotSupportedImageFormatExceptionRepresents an exception thrown when attempting to use an image format that is not supported by the library.
InvalidAnnotationExceptionRepresents an exception for an annotation that is not valid.
NotSupportedAnnotationExceptionRepresents an exception for an annotation that is not supported.
InvalidImageDataExceptionRepresents an exception for importing invalid image data.
NotSupportedPdfPrimitivesConversionExceptionRepresents an exception thrown when attempting to convert unsupported PDF primitive types.
InvalidStructureTreeExceptionThrown when the PDF structure tree contains invalid or malformed elements during import. This exception wraps lower-level errors such as invalid page references or object references encountered while parsing the document logical structure.
InvalidObjectReferenceExceptionThrown when a PDF object reference is invalid during import or processing. This occurs when a structure element object reference points to an unrecognized object type.
InvalidPageReferenceExceptionThrown when a PDF page reference is invalid during import or processing. This occurs when a structure element Page property references a non-page object.

See Also