I have a UIViewController containing a UIWebView which I am using to view various documents. Occasionally a document may attempt to be loaded which is not supported by the UIWebView (e.g. old Excel 2.0 sheet). Currently this causes output in the debug window as follows :
exception: CPMessageException: The file format is invalid.
EXCEPTION CPMessageException: (null)
The webViewDidStartLoad method fires, but neither webViewDidFinishLoad or didFailLoadWithError fires.
The error doesn't crash the app, but I would like to trap this exception to provide my own message for the user. Can anybody suggest how to trap and handle this?
Many thanks, Jonathan
Unfortunately CPMessageException is part of the private frameworks of Apple, in case of office files, OfficeImport.framework. This is thrown when the framework receives an unusable file.
The reason your application is not crashing is because it is probably being handled in the import code itself. Even setting NSSetUncaughtExceptionHandler will not work (as I have tried in the past).
The best way to go around this would be to use the shouldStartLoadWithRequest delegate method of UIWebView:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Here you could preemptively stop the file from being loaded into the web view and avoid a clueless blank screen.
(Am not sure if there is a way to read NSLog output on the fly so you could monitor it. But that is probably not a right way to do it!)
Update: Just filed a bug regarding this. Let us see what the Apple Developers have to say on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With