Fixed infinite loop of recursive exception handler calls from locking up

my window system and forcing me to restart it


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8553 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2001-01-10 22:37:29 +00:00
parent b29ceb3c09
commit f3617dfe1a

View file

@ -71,13 +71,13 @@
#include <AppKit/NSDataLinkPanel.h> #include <AppKit/NSDataLinkPanel.h>
#include <AppKit/NSHelpPanel.h> #include <AppKit/NSHelpPanel.h>
static void /*
_preventRecursion (NSException *exception) * Base library exception handler
{ */
} static NSUncaughtExceptionHandler *defaultUncaughtExceptionHandler;
/* /*
* AppKit exception handler (overrides Foundation) * Gui library user friendly exception handler
*/ */
static void static void
_NSAppKitUncaughtExceptionHandler (NSException *exception) _NSAppKitUncaughtExceptionHandler (NSException *exception)
@ -90,26 +90,33 @@ _NSAppKitUncaughtExceptionHandler (NSException *exception)
#define DEBUG_BUTTON nil #define DEBUG_BUTTON nil
#endif #endif
/* Reset the exception handler to the Base library's one, to prevent
recursive calls to the gui one. */
NSSetUncaughtExceptionHandler (defaultUncaughtExceptionHandler);
/* /*
* If there is no graphics context to run the alert panel in, * If there is no graphics context to run the alert panel in,
* use the default exception handler. * use the default exception handler.
*/ */
if (GSCurrentContext() == nil) if (GSCurrentContext() == nil)
{ {
_NSUncaughtExceptionHandler = _preventRecursion; defaultUncaughtExceptionHandler (exception);
fprintf(stderr, "Uncaught exception %s, reason: %s\n",
[[exception name] lossyCString], [[exception reason] lossyCString]);
exit(1);
} }
retVal = NSRunCriticalAlertPanel([[NSProcessInfo processInfo] processName], retVal = NSRunCriticalAlertPanel ([[NSProcessInfo processInfo] processName],
@"%@: %@", @"%@: %@",
@"Abort", @"Ignore", DEBUG_BUTTON, @"Abort", @"Ignore", DEBUG_BUTTON,
[exception name], [exception reason]); [exception name], [exception reason]);
/* The user wants to abort */
if (retVal == NSAlertDefault) if (retVal == NSAlertDefault)
{ {
abort(); defaultUncaughtExceptionHandler (exception);
} }
/* The user said to go on - more fun I guess - turn the AppKit
exception handler on again */
NSSetUncaughtExceptionHandler (_NSAppKitUncaughtExceptionHandler);
} }
/* /*
@ -297,8 +304,12 @@ static NSCell* tileCell = nil;
NSDebugLog(@"Initialize NSApplication class\n"); NSDebugLog(@"Initialize NSApplication class\n");
[self setVersion: 1]; [self setVersion: 1];
// Set the AppKit exception handler. /* Save the base library exception handler */
_NSUncaughtExceptionHandler = _NSAppKitUncaughtExceptionHandler; defaultUncaughtExceptionHandler = NSGetUncaughtExceptionHandler ();
/* Set a new exception handler for the gui library */
NSSetUncaughtExceptionHandler (_NSAppKitUncaughtExceptionHandler);
/* Cache the NSAutoreleasePool class */ /* Cache the NSAutoreleasePool class */
arpClass = [NSAutoreleasePool class]; arpClass = [NSAutoreleasePool class];
nc = [NSNotificationCenter defaultCenter]; nc = [NSNotificationCenter defaultCenter];