adium 3722:ec2f74b4d770: Log all exceptions to the debug log wit...

commits at adium.im commits at adium.im
Thu Mar 10 21:15:44 UTC 2011


details:	http://hg.adium.im/adium/rev/ec2f74b4d770
revision:	3722:ec2f74b4d770
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Thu Mar 10 22:15:35 2011 +0100

Log all exceptions to the debug log with a backtrace.

It would be preferable to crash on all uncaught exceptions, but HIToolbox catches all exceptions from the GUI. This is better than nothing.

diffs (52 lines):

diff -r f688c7e6e4e6 -r ec2f74b4d770 Source/ESDebugController.m
--- a/Source/ESDebugController.m	Wed Mar 09 13:37:36 2011 +0200
+++ b/Source/ESDebugController.m	Thu Mar 10 22:15:35 2011 +0100
@@ -26,6 +26,8 @@
 
 #import <objc/objc-runtime.h>
 
+#import <ExceptionHandling/NSExceptionHandler.h>
+
 #define	CACHED_DEBUG_LOGS		100		//Number of logs to keep at any given time
 #define	KEY_DEBUG_WINDOW_OPEN	@"Debug Window Open"
 
@@ -49,11 +51,38 @@
 		objc_setEnumerationMutationHandler(AIExplodeOnEnumerationMutation);
 #endif
 
-		debugLogArray = [[NSMutableArray alloc] init];		
+		debugLogArray = [[NSMutableArray alloc] init];
+		
+		NSExceptionHandler *exceptionHandler = [NSExceptionHandler defaultExceptionHandler];
+		
+		NSUInteger handlingMask = NSLogUncaughtExceptionMask | NSLogUncaughtSystemExceptionMask | NSLogUncaughtRuntimeErrorMask
+								  | NSLogTopLevelExceptionMask | NSLogOtherExceptionMask;
+
+		[exceptionHandler setExceptionHandlingMask:handlingMask];
+		[exceptionHandler setDelegate:self];
 	}
 	return self;
 }
 
+#pragma mark Exception Handling
+
+/*!
+ * @brief HIToolbox intercepts all exceptions coming from the GUI, even if crashing would be prefered.
+ *
+ * However, logging them with backtrace to the debug log is better than nothing.
+ */
+- (BOOL)exceptionHandler:(NSExceptionHandler *)sender shouldLogException:(NSException *)exception mask:(NSUInteger)aMask
+{
+	AILogWithSignature(@"Exception raised: %@", exception);
+	AILogBacktrace();
+	
+	NSLog(@"Exception was raised: %@", exception);
+	
+	return NO;
+}
+
+#pragma mark -
+
 - (void)controllerDidLoad
 {
 	if (AIDebugLoggingEnabled) {




More information about the commits mailing list