discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

exception handling


From: Aurelien
Subject: exception handling
Date: Tue, 4 Sep 2001 15:07:27 +0200

Hi,

I'm trying the following to test exception handling, without success:

- (PeerGroupAdvertisement *) fixAdvertisement:(PeerGroupAdvertisement *) adv
{
  NSException *exc;
  if ( adv == NULL ) {
    NS_DURING
      NSLog (  @"Trying to crete a new advertisement with type..." );
exc = [[NSException alloc] initWithName:@"haha" reason:@"bubu" userInfo:NULL];
      [exc raise];
adv = (PeerGroupAdvertisement *) [AdvertisementFactory newAdvertisementWithType:[PeerGroupAdvertisement getAdvertisementType]];
     NS_HANDLER
       NSLog ( @"Cannot create a new platform advertisement" );
     NS_ENDHANDLER
  }
}

Oh and, yes, I never know when to use nil or NULL...

The above code doesn't work as expected (or as I expect it to work), that is the HANDLER block doesn't get executed and I don't get the message "Cannot create a new platform advertisement".

In Apple's doc, they say you have to be sure your compiler handles longjmp. But I don't know how to check for that... (I use gcc 3.1 besides) Also, I'd like to know more about the differences between exceptions and assertions.

thx for helping a poor beginner,

Aurélien



reply via email to

[Prev in Thread] Current Thread [Next in Thread]