* Source/NSApplication.m: Added code to handle exceptions in

-[NSApplication run].  Rudimentary implementation of default
	NSExceptionHandlerMask.

For more on this change, please see the thread on the gnustep-dev list entitled "Allowing Applications to continue after exception...".


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27809 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2009-02-08 06:40:29 +00:00
parent 71f807b1c7
commit 6bec341a72
2 changed files with 59 additions and 12 deletions

View file

@ -1,3 +1,9 @@
2009-02-08 01:17-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSApplication.m: Added code to handle exceptions in
-[NSApplication run]. Rudimentary implementation of default
NSExceptionHandlerMask.
2009-02-07 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Additions/GNUstepGUI/GSTheme.h,

View file

@ -1361,6 +1361,38 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
userInfo: [self _notificationUserInfo]];
}
#define NSLogUncaughtExceptionMask 1
#define NSHandleUncaughtExceptionMask 2
#define NSLogUncaughtSystemExceptionMask 4
#define NSHandleUncaughtSystemExceptionMask 8
#define NSLogRuntimeErrorMask 16
#define NSLogUncaughtRuntimeErrorMask 32
/**
* Private method to handle an exception which occurs in the application runloop.
*/
- (void) _handleException: (NSException *)exception
{
int mask = [[NSUserDefaults standardUserDefaults] integerForKey: @"NSExceptionHandlerMask"];
/**
* If we are in debug mode, then rethrow the exception so that
* the application can be stopped.
**/
// log the exception.
if(mask & NSLogUncaughtExceptionMask)
{
[self reportException: exception];
}
// allow the default handler to handle the exception.
if(mask & NSHandleUncaughtExceptionMask)
{
[exception raise];
}
}
/*
* Running the main event loop
*/
@ -1378,7 +1410,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
{
NSEvent *e;
id distantFuture = [NSDate distantFuture]; /* Cache this, safe */
if (_runLoopPool != nil)
{
[NSException raise: NSInternalInconsistencyException
@ -1409,24 +1441,33 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
IF_NO_GC(_runLoopPool = [arpClass new]);
e = [self nextEventMatchingMask: NSAnyEventMask
untilDate: distantFuture
inMode: NSDefaultRunLoopMode
dequeue: YES];
untilDate: distantFuture
inMode: NSDefaultRunLoopMode
dequeue: YES];
if (e != nil && e != null_event)
{
NSEventType type = [e type];
[self sendEvent: e];
// Catch and report any uncaught exceptions.
NS_DURING
{
[self sendEvent: e];
// update (en/disable) the services menu's items
if (type != NSPeriodic && type != NSMouseMoved)
{
[_listener updateServicesMenu];
[_main_menu update];
// update (en/disable) the services menu's items
if (type != NSPeriodic && type != NSMouseMoved)
{
[_listener updateServicesMenu];
[_main_menu update];
}
}
NS_HANDLER
{
[self _handleException: localException];
}
NS_ENDHANDLER;
}
DESTROY (_runLoopPool);
}