Here is the promised patch.   Please take a look and give any feedback you
can.

This is simply a patch to allow the user to set whether or not they want to
debug exceptions or not.  The default is NO at present so the exceptions
will simply be logged as they are in Cocoa.

I am going to go ahead and commit this change fairly soon (probably early
tomorrow morning) after I do more testing.  If it causes problems for anyone
then we can revert it.  I know this goes a bit against what I said earlier
(about sending a patch), but I would like to get this in very soon and it's
easier for people to examine if it's in the repository.

Later, GC

On Fri, Feb 6, 2009 at 2:40 PM, Gregory Casamento
<greg.casame...@gmail.com>wrote:

> My test application doesn't link with the ExceptionHandling framework at
> all....
>
> So, it looks like we have two things going on here under Cocoa/OpenStep:
>
> 1) The standard/default exception handler generally just logs the exception
> and continues... as illustrated by my example code.
> 2) The ExceptionHandling.framework allows us to handle exceptions in a more
> finely grained manner by replacing the standard/default exception handler
> with one that can talk to the delegate.  (if the application links with the
> ExceptionHandling.framework)
>
> So it seems that implementing part 1 and 2 are not interdependent on one
> another.
>
> Is anyone else getting that impression?
>
> GC
>
>
> On Fri, Feb 6, 2009 at 10:51 AM, Wolfgang Lux <wolfgang....@gmail.com>wrote:
>
>> Gregory Casamento wrote:
>>
>>  What should "NSExceptionMask" be implemented as?  SHould it be a boolean
>>> that determines if we should allow the application to continue or not?
>>>
>>> That is to say
>>> * NSExceptionMask = YES  - report all exceptions, but continue anyway...
>>> * NSExceptionMask = NO - current behavior
>>>
>>> If so, I have a patch almost ready.  I'll submit it to the group prior to
>>> committing it since a change that is this important needs to have some
>>> amount of consensus.
>>>
>>
>> Have a look at Apple's ExceptionHandlingFramework, which is described
>> here:
>>
>>  http://developer.apple.com/documentation/Cocoa/Reference/
>> ExceptionHandlingFramework/index.html
>>
>> Implementation of this framework looks very straight forward, and I guess
>> that they simply install the defaultExceptionHandler in the event loop of
>> NSApplication.
>>
>> The NSExceptionHandlingMask (not NSExceptionMask!) default is described in
>> the accompanying guide that Richard mentioned already:
>>
>>  http://developer.apple.com/documentation/Cocoa/Conceptual/
>> Exceptions/Exceptions.html
>>
>> In particular, see the section "Controlling a Program's Response to
>> Exceptions".
>>
>> Essentially, NSExceptionHandlingMask is a bit mask that controls whether
>> uncaught exceptions, uncaught system exceptions, and runtime errors are
>> logged and/or handled. The important values (quoted from the above document)
>> are
>>
>>  #define NSLogUncaughtExceptionMask 1
>>  #define NSHandleUncaughtExceptionMask 2
>>  #define NSLogUncaughtSystemExceptionMask 4
>>  #define NSHandleUncaughtSystemExceptionMask 8
>>  #define NSLogRuntimeErrorMask 16
>>  #define NSLogUncaughtRuntimeErrorMask 32
>>
>> Wolfgang
>>
>>
>
>
> --
> Gregory Casamento
> Open Logic Corporation, Principal Consultant
> ## GNUstep Chief Maintainer
> yahoo/skype: greg_casamento, aol: gjcasa
> (240)274-9630 (Cell), (301)362-9640 (Home)
>
>


-- 
Gregory Casamento
Open Logic Corporation, Principal Consultant
## GNUstep Chief Maintainer
yahoo/skype: greg_casamento, aol: gjcasa
(240)274-9630 (Cell), (301)362-9640 (Home)
Index: Source/NSApplication.m
===================================================================
--- Source/NSApplication.m	(revision 27805)
+++ Source/NSApplication.m	(working copy)
@@ -126,6 +126,7 @@
       [exception raise];
     }
 
+  /*
   retVal = GSRunExceptionPanel 
     ([NSString stringWithFormat: _(@"Critical Error in %@"),
 	       [[NSProcessInfo processInfo] processName]],
@@ -137,18 +138,19 @@
 #else
      nil);
 #endif
+  */
 
   /* The user wants to abort */
   if (retVal == NSAlertDefault)
     {
       /* The following will raise again the exception using the base 
 	 library exception handler */
-      [exception raise];
+      // [exception raise];
     }
   else
     {
       /* Debug button: abort so we can trace the error in gdb */
-      abort();
+      // abort();
     }
 }
 
@@ -1378,7 +1380,8 @@
 {
   NSEvent *e;
   id distantFuture = [NSDate distantFuture];     /* Cache this, safe */
-  
+  BOOL debug = [[NSUserDefaults standardUserDefaults] boolForKey: @"GSDebugException"];
+
   if (_runLoopPool != nil)
     {
       [NSException raise: NSInternalInconsistencyException
@@ -1409,16 +1412,31 @@
       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];
-
+	  NS_DURING
+	    {	  	  
+	      [self sendEvent: e];
+	    }
+	  NS_HANDLER
+	    {
+	      if(debug)
+		{
+		  [localException raise];
+		}
+	      else
+		{
+		  NSLog(@"NSApplication caught an unhandled exception: %@",
+			localException);
+		}
+	    }
+	  NS_ENDHANDLER;
+	  
 	  // update (en/disable) the services menu's items
 	  if (type != NSPeriodic && type != NSMouseMoved)
 	    {
@@ -1426,7 +1444,7 @@
 	      [_main_menu update];
 	    }
 	}
-
+      
       DESTROY (_runLoopPool);
     }
 
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to