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

54 views
Skip to first unread message

Ryan

unread,
Feb 7, 2017, 8:20:17 PM2/7/17
to PDFTron PDFNet SDK
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:

Diego Dias

unread,
May 18, 2017, 9:33:25 PM5/18/17
to PDFTron PDFNet SDK
The post doesn't answer the question. 
And I have the same question. 
Do you found some solution for that, Ryan?

Ryan

unread,
May 25, 2017, 3:11:47 PM5/25/17
to PDFTron PDFNet SDK
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 PTPDFNetcatchException.

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
PTPDFNet catchException.m
Reply all
Reply to author
Forward
0 new messages