In my applicationDidFinishLaunching: I am creating the Application Support directory and I want to handle the case where the directory can't be created. (I am working on an application for my MacBook Pro.)
I found one possible tip in "Cocoa Design Patterns" (p. 253.) The sample code uses NSRunAlertPanel(). I'd like to display an alert and then perform an exit(1). (Somewhere I need to handle a click on a "Quit" button in the Alert.) I'm sure there will be other cases where very unusual catastrophic, but highly unlikely, conditions necessitate an abnormal termination of the program, so I should probably be writing a general way of handling such events. I hope I'm on the right track. Thanks all for your replies. On Thu, Apr 29, 2010 at 1:48 PM, Fritz Anderson <fri...@manoverboard.org> wrote: > On 29 Apr 2010, at 1:31 PM, Paul Johnson wrote: > >> I would like to have some guidance on the proper way to 'gracefully' >> terminate a program that cannot proceed, for example, when some >> critical resource can't be created or doesn't exist. >> >> I've look through all my reference books and searched the internet for >> sample code but have come up empty handed. Thanks for your assistance. > > Your bad luck probably has to do with the vagueness of what you're asking, > compared with the specific failures you want to handle. > > iPhone or Mac? > > What kind of "critical resource?" A configuration file, code, media... ? > > Is it something you expect to find in your application bundle, something over > the network, in the file system... ? > > Is it something for which you can provide a default or stop-gap substitute, > so you can at least survive to put up an alert? > > Is it known for its work in the theater? > > What kind of "cannot proceed?" Will crash immediately, can't support the > user's request, will corrupt data... ? > > What, in short, is it? > > Off the top of my head, the Right Things are: > > * Preflight the availability of the resource, and disable the commands that > would require it. > > * Back out of the task that resulted in the missing resource, if possible, > and post an alert explaining what can't be done, why, and how to fix it. > > * If the application can't proceed in any way (not even to the extent of > access to commands or preferences that might fix the problem), always post an > alert saying so. On the Mac, provide a Quit button. On the iPhone, post an > alert explaining the situation, and advise the user to press the Home button; > present an inert (empty if necessary) UI if the user dismisses the alert > instead. > > * Provide some facilities for self-repair, preferably from within application > commands or preferences. > > * Don't terminate a Mac application without an explanation. The only way to > terminate an iPhone application is to call abort(), which I believe could be > a reason to reject it from the App Store. > > — F > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com