bug-gnustep
[Top][All Lists]
Advanced

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

Recursive Exeption raising


From: Markus Hitter
Subject: Recursive Exeption raising
Date: Wed, 20 Mar 2002 16:41:13 +0100

Hello,

in my efforts to port GNUstep base to Darwin, I managed to cause recursively raised exceptions, because the exception handling code tries to create a new NSString which again raises ...

Of course, some of my code is broken, but this is why Exceptions exist, don't they?


I found a solution which works for me (see below) but I'm not fully satisfied:

1) Don't know what to do in case of a recursive exception except for abort().

2) The name of the exception might be an insufficient identifier.

3) A clean solution wouldn't create new objects except the NSException itsself and this avoid the chance for recursion at all.


Here's the modified method for NSException for discussion or use:

+ (void) raise: (NSString*)name
        format: (NSString*)format
     arguments: (va_list)argList
{
  // don't fiddle with malloc() in this critical situation
  static unsigned char lastName[64];
  NSString      *reason;
  NSException   *except;

  /* Avoid recursive Exception raising. This works as long as
long as all NSString methods raise their exception using this method. */
  if (strncmp(lastName, [name cString], 63))
    {
      strncpy(lastName, [name cString], 63);
    } else {
      fprintf(stderr, "Recursive Exception detected.\n");
      fprintf(stderr, "Name: %s\nReason: ", lastName);
      vfprintf(stderr, [format cString], argList);
      abort();
    }

  /* Creating a new NSString here can lead to a recursion */
  reason = [NSString stringWithFormat: format arguments: argList];
  except = [self exceptionWithName: name reason: reason userInfo: nil];
  [except raise];
}


Cheers,
Markus




P.S.: This is the backtrace I get now instead of the 5176 line one before:

#0  0x7001a70c in kill ()
#1  0x7006f990 in abort ()
#2  0x001e6390 in -[NSException initWithName:reason:userInfo:] ()
#3  0x7006f990 in abort ()
#4  0x002054ec in -[NSObject(GNU) subclassResponsibility:] ()
#5  0x0021f578 in -[NSString length] ()
#6  0x0021ef00 in -[NSString initWithFormat:locale:arguments:] ()
#7  0x0021eeb4 in -[NSString initWithFormat:arguments:] ()
#8  0x0021e740 in +[NSString stringWithFormat:arguments:] ()
#9  0x001e62ec in +[NSException raise:format:arguments:] ()
#10 0x001e6244 in +[NSException raise:format:] ()
#11 0x002054ec in -[NSObject(GNU) subclassResponsibility:] ()
#12 0x0021f578 in -[NSString length] ()
#13 0x001c02fc in +[NSCharacterSet characterSetWithCharactersInString:] ()
#14 0x0021dfa4 in pathSeps ()
#15 0x00222600 in -[NSString lastPathComponent] ()
#16 0x00212554 in _gnu_process_args ()
#17 0x00212874 in main ()
#18 0x000029cc in _start ()
#19 0x000027fc in start ()

This is what is now shown on the console:
Recursive Exception detected.
Name: NSGenericException
Reason: subclass NSConstantString(instance) should override length
basic has exited due to signal 6 (SIGABRT).

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/





reply via email to

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