Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: longjmp exit



On Jul 30, 2005, at 8:35 AM, Roland Silver wrote:
I'm adapting an old C-program to Cocoa. My program uses the longjmp mechanism to force an exit in case of a serious error. Is there a different, more appropriate, mechanism in Cocoa?

It depends on how catastrophic of a failure the current longjmp() mechanism indicates.


If it implies a "friendly termination", which is unlikely, then invoking -terminate on NSApp will work.

On the other hand, if it means that execution should terminate immediately without further "high level" execution, then exit() will work quite well. Even with exit(), there is still the opportunity for code to be executed to the point where the runloop could be re- entered.

So, if you really want to ensure that process will quit, use _Exit() or _exit(). _Exit() will exit immediately without cleanup. _exit() cleans up quite a bit. Apparently, _exit() cleans up more than exit (), but will not invoke atexit() handlers.

Finally, if you really want the program to stop execution right then and there, use abort(). Except abort() can be caught by installing a SIGABRT handler.

man 3 exit
man _exit
man _Exit
man abort
man sysexits # this will tell you what exit code you should use

b.bum




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >longjmp exit (From: Roland Silver <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.