Re: Uncaught exceptions not terminating my app
Re: Uncaught exceptions not terminating my app
- Subject: Re: Uncaught exceptions not terminating my app
- From: Ken Thomases <email@hidden>
- Date: Wed, 20 Jan 2010 14:01:44 -0600
On Jan 20, 2010, at 1:27 PM, Paul Sanders wrote:
> I am experiencing a strange problem with the handling of uncaught exceptions which I'm hoping someone can shed some light on.
>
> This document:
>
> http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/Exceptions/Tasks/ControllingAppResponse.html#//apple_ref/doc/uid/20000473
>
> states that certain classes of exception will terminate the app if they are not caught.
But the main application loop is documented as catching all exceptions that reach it. One example of the documentation is the note on this page:
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/Exceptions/Concepts/UncaughtExceptions.html#//apple_ref/doc/uid/20000056
> But this is not the behaviour I observe. To take a specific example, executing this code:
>
> [NSObject noSuchSelector];
> foo ();
>
> Just abruptly returns to the main event loop (and the call to foo (), and whatever follows, is never executed).
Right. As documented.
> This is _not_ the behaviour I want. If I am stupid enough to send a message to an object that doesn't recognise it, I'd like my program to crash (and therefore generate a crash log). Then, when it restarts, it offers to send the log to me (thank you, Uli M Kusterer). Otherwise, my app will just behave strangely and I will never even know I have a bug. Exit one [potential] customer.
I don't know if there's a way to prevent NSApplication from catching exceptions in the main event loop. You can override -reportException: to call abort() or the like, but a) somebody here recently reported that their -reportException: override wasn't being called on Snow Leopard, and b) the abort() will produce a crash report that doesn't show the call stack which generated the original exception -- it will show the call stack for the abort() call, which is uninteresting.
You can compensate for (b) by logging the actual exception, perhaps with the help of NSExceptionHandler to add a stack trace. Maybe you can hack together an override of -[NSApplication run] to get rid of the top-level exception handling?
Certainly, you can use NSExecptionHandler to log all exceptions which get caught by the top-level exception handler, and then you can send yourself that log in lieu of a crash report.
-Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden