How do I catch errors/exceptions from the OCX/COM components (XpdfViewer, XpdfPrint, etc.)?

Applies to: XpdfViewer, XpdfPrint, XpdfRasterizer, XpdfText, XpdfAnalyze, XpdfImageExtract, XpdfInfo, XpdfPS

The Xpdf OCX/COM components use standard COM exceptions. To catch exceptions in VB6:

        On Error GoTo err
        ...
        XpdfPrintObj.loadFile fileName
        ...
    err:
        If Err = XpdfPrintObj.errOpenFile Then
            ' ... couldn't open the file ...
        End If

In VB.net:

    Try
        XpdfPrintObj.loadFile(fileName)
    Catch e As System.Runtime.InteropServices.COMException
        If e.ErrorCode = XpdfPrintObj.errOpenFile Then
            // ... couldn't open the file ...
        End If
    End Try

In C#:

    using System.Runtime.InteropServices;
    ...
    try {
        XpdfPrintObj.loadFile(fileName);
    } catch (COMException e) {
        if (e.ErrorCode == XpdfPrintObj.errOpenFile) {
            // ... couldn't open the file ...
        }
    }