Re: exception in init
Re: exception in init
- Subject: Re: exception in init
- From: Ariel Feinerman <email@hidden>
- Date: Thu, 05 Apr 2012 16:59:24 +0400
Thank for your all and especially Jens answers
the next provocative question is whether can we release self in init before
raise an exception? I think it has own reason.
On Thu, Apr 5, 2012 at 12:05 PM, Andreas Grosam <email@hidden>wrote:
>
> On Apr 4, 2012, at 7:33 PM, Corbin Dunn wrote:
>
> >
> > On Apr 4, 2012, at 9:29 AM, Andreas Grosam <email@hidden>
> wrote:
> >
> >> The problem on Mac OS X in Cocoa Apps is, that there is no alert. The
> application also does not stop, or terminate gracefully. The default
> behavior of the event loop is to log an error message, and then
> **continue**.
> >
> > No, there is an alert! you just have to turn it on. From:
> >
> > https://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKit.html
> >
> > "AppKit now has the ability to report uncaught exceptions. It is
> controlled by a user default: NSApplicationShowExceptions (YES/NO). The
> default shipping value is NO. In general, it is recommend that developers
> set it to YES during development to catch programming errors. Individual
> applications can automatically turn this on by using [[NSUserDefaults
> standardUserDefaults] registerDefaults: ...] to register the option on. It
> can be set with defaults via: 'defaults write com.yourdomain.app
> NSApplicationShowExceptions YES'. It can also globally be turned on by
> writing to the global domain."
> >
> > --corbin
>
>
> I'm obviously missing something. I've the following code in a Mac OS X
> App, which I created straight from an Xcode template:
>
> In AppDelegate.m:
>
> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
> {
> NSDictionary* defaults = [NSDictionary dictionaryWithObjectsAndKeys:
> [NSNumber numberWithBool:YES],
> @"NSApplicationShowExceptions",
> nil];
> [[NSUserDefaults standardUserDefaults] registerDefaults: defaults];
> [[NSUserDefaults standardUserDefaults] synchronize];
>
>
> if (test_ == nil) {
> test_ = [[JTTest alloc] initWithString:nil]; // throws if
> parameter string equals nil
> }
> }
>
>
> And in JTTest.m:
>
> - (id)initWithString:(NSString*)string
> {
> self = [super init];
> if (self) {
> if (string == nil) {
>
> //NSParameterAssert(string); alternatively
>
> NSException* myException = [NSException
> exceptionWithName:@"Invalid
> Parameter"
> reason:@"parameter 'string' is nil"
> userInfo:nil];
> @throw myException;
>
> }
> string_ = [string retain];
> }
> return self;
> }
>
>
>
> The application starts and immediately throws an exception. There is a log
> in the console as expected - but there is NO alert and the app continues.
>
> Additionally, I also enabled the flag NSApplicationShowExceptions in the
> global domain via
>
> $ defaults write -g NSApplicationShowExceptions YES
>
> in the console and launched the test app via
>
> $ open test.app
>
> I'm on Mac OS X, 10. 7.3. There is NO alert.
>
>
>
> Andreas
>
> _______________________________________________
>
> 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
>
--
best regards
Ariel
_______________________________________________
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