bugGNUstep - Bugs: bug #23314, Problem handling exceptions with...

Group
 
 

bug #23314: Problem handling exceptions with own handler

Submitter:  UBoss <uboss>
Submitted:  Wed 21 May 2008 12:04:28 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Declined
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 21 May 2008 01:45:58 PM UTC, comment #3: 

When trying to debug an application and find out where exceptions are raised, you can set the GNUSTEP_STACK_TRACE environment variable to YES (to get a printout of the stacktrace logged) or (better probably) you can run the program under gdb (or attach gdb to the running program) and set a break point in the -raise method.

Richard Frith-Macdonald <CaS>
Group Member
Wed 21 May 2008 01:29:46 PM UTC, comment #2: 

So if I understend it correct I can't catch exception in _NSUncaughtExceptionHandler when in notification handler.

So I post notifictation doSomething to myAPP and in method
doSomething:(NSNotification *)aNot ... which is hanlder of this notification
all possible exceptions is handled in NSNotificationCenter, where only NSLog is printed but I need to track down why there is an exception.

What is elegenat solution for this problem, if I don't want to close all possibilities to NS_DURING NS_HANDLER ... ?

UBoss <uboss>
Wed 21 May 2008 12:47:22 PM UTC, comment #1: 

Looks like you are raising the exception within a notification handler.
Exceptions occurring within timeouts or notifications are handled locally (logged and ignored) by the base library (Foundation framework on macos-x).
So the exception is caught by the NSNotificationCenter and handled there.
Therefore, as this is not an uncaught exception, it is not (and should not be) dealt with by the uncaught exception handler.


Richard Frith-Macdonald <CaS>
Group Member
Wed 21 May 2008 12:04:28 PM UTC, original submission:  

When instaled own handler

static void myExceptionHandler (NSException *exception)
{
    FILE *fw;
    NSLog (@"Osetruji exception ...\n%@", exception);
    fw = fopen ("exception.err", "a");
    fprintf (fw, [[NSString stringWithFormat:@"%@ -> ERROR:\n%@\n", [NSDate date], exception] cString]);
    fclose (fw);
    abort ();
}

with

     NSSetUncaughtExceptionHandler(&myExceptionHandler);

or

    _NSUncaughtExceptionHandler = myExceptionHandler;

and then call

    [NSException raise:NSInternalInconsistencyException
    format:@"TEST TEST TEST"];

the handler myExceptionHandler is not called,
insted of message
 Osetruji exception ...
<NSException: 0x8540070> NAME:NSInternalInconsistencyException REASON:TEST TEST TEST INFO:(nil)
Abort (core dumped)

I got mesasge
Problem posting notification: <NSException: 0                                     x85400f0> NAME:NSInternalInconsistencyException REASON:TEST TEST TEST INFO:(nil)

it has something to do with NSNotificationCeneter.m _postAndRelease method

...
      if (o->next != 0)
        {
         NS_DURING
            {
              (*o->method)(o->observer, o->selector, notification);
            }
          NS_HANDLER
            {
              NSLog(@"Problem posting notification: %@", localException);
            }
          NS_ENDHANDLER
...

when removed NS_DURING and NS_HANDLER ... NS_ENDHANDLER

the handler myExceptionHandler is called again.





UBoss <uboss>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by uboss (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-05-21 CaS StatusNone Invalid
        Open/ClosedOpen Declined

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code