I am unable to catch exceptions using PDFNet and Swift on iOS

Question:

I tried putting it between a try-catch:

do{ let doc=try PTPDFDoc(filepath: url) }catch{ }

But the error isn’t handled, furthermore the compiler alerts me this:

No calls to throwing functions occur within 'try' expression

Answer:

Please see this blog post
https://blog.pdftron.com/2014/09/22/using-pdfnet-from-a-swift-project-on-ios/

The post doesn’t answer the question.
And I have the same question.
Do you found some solution for that, Ryan?

Thank you for bringing this to our attention.

Please add the attached category files to your Swift project, and include the header in your bridging header. The category will add a new class method to PTPDFNet, catchException.

You can then use the following pattern to handle exceptions thrown by PDFNet:

do { try PTPDFNet.catchException { // code that may throw an exception doc = PTPDFDoc(filepath: docPath!) } } catch { print("Caught exception") }

This method will be included in the next version of PDFNet (without the need to add it via a category).

PTPDFNet catchException.h (473 Bytes)

PTPDFNet catchException.m (770 Bytes)