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

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #23314: Problem handling exceptions with own handler

Submitted by:  UBoss <uboss>
Submitted on:  Wed 21 May 2008 12:04:28 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: NoneStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Declined

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>
Project 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>
Project 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>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 21 May 2008 12:47:22 PM UTCCaSStatusNone=>Invalid
      Open/ClosedOpen=>Declined

    Back to the top


    Powered by Savane 3.1-cleanup1