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

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

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 ... } }

In unmanaged C++:

try { XpdfPrintObj->loadFile(fileName); } catch (_com_error e) { if (e.Error() == XpdfPrintObj->errOpenFile) { // ... couldn't open the file ... } }