3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
7 #import "HBApplication.h"
8 #import "HBExceptionAlertController.h"
9 #import "HBUtilities.h"
11 @implementation HBApplication
13 static void CrashMyApplication()
18 - (NSAttributedString *)_formattedExceptionBacktrace:(NSArray *)backtrace
20 NSMutableAttributedString *result = [[NSMutableAttributedString alloc] init];
21 for (__strong NSString *s in backtrace)
23 s = [s stringByAppendingString:@"\n"];
24 NSAttributedString *attrS = [[NSAttributedString alloc] initWithString:s];
25 [result appendAttributedString:attrS];
27 [result addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Monaco" size:10] range:NSMakeRange(0, result.length)];
31 - (void)reportException:(NSException *)exception
33 // NSApplication simply logs the exception to the console. We want to let the user know
34 // when it happens in order to possibly prevent subsequent random crashes that are difficult to debug
39 // Create a string based on the exception
40 NSString *exceptionMessage = [NSString stringWithFormat:@"%@\nReason: %@\nUser Info: %@", exception.name, exception.reason, exception.userInfo];
41 // Always log to console for history
43 [HBUtilities writeToActivityLog:"Exception raised:\n%s", exceptionMessage.UTF8String];
44 [HBUtilities writeToActivityLog:"Backtrace:\n%s", exception.callStackSymbols.description.UTF8String];
46 HBExceptionAlertController *alertController = [[HBExceptionAlertController alloc] init];
47 alertController.exceptionMessage = exceptionMessage;
48 alertController.exceptionBacktrace = [self _formattedExceptionBacktrace:exception.callStackSymbols];
50 NSInteger result = [alertController runModal];
51 if (result == HBExceptionAlertControllerResultCrash)
57 @catch (NSException *e)
59 // Suppress any exceptions raised in the handling