-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrashLoggerUtilities.m
37 lines (30 loc) · 1.49 KB
/
CrashLoggerUtilities.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "CrashLoggerUtilities.h"
@implementation CrashLoggerUtilities
+ (NSString*) NSExceptionToString: (NSException*) exception{
// Converting array of call-stack lines into formatted string (using Fast Enumeration and integer is faster than traditional objectAtIndex)
NSMutableString * strCallStackSymbols =[[NSMutableString alloc] init];
for (NSString* callStackSymbol in exception.callStackSymbols)
{
[strCallStackSymbols appendFormat:@"%@\n", callStackSymbol];
}
// Converting array of call-stack return addresses into formatted string
NSMutableString * strCallStack =[[NSMutableString alloc] init];
NSUInteger callStackIndex=0;
for (NSNumber* callStackReturnAddress in exception.callStackReturnAddresses)
{
[strCallStack appendFormat:@"%lu) %qX ",callStackIndex,[callStackReturnAddress longLongValue]];
callStackIndex++;
}
// Constructing full exception string info
NSMutableString* exceptionString=[[NSMutableString alloc] initWithFormat:
@"Name: %@\n"
"Reason: %@\n"
"User info: %@\n"
"Throwed exception type: %@\n"
"Functions stack:\n%@\n"
"Call stack's return addresses:\n%@\n",
exception.name, exception.reason, exception.userInfo, exception.class, strCallStackSymbols, strCallStack];
//exception.name, exception.reason, exception.userInfo, exception.class, exception.callStackSymbols, exception.callStackReturnAddresses]; // Non-formatted
return exceptionString;
}
@end