-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExceptionHandler.m
64 lines (54 loc) · 1.79 KB
/
ExceptionHandler.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// ExceptionHandler.m
// iOS_SDK
//
// Created by ANH TU on 9/26/15.
// Copyright (c) 2015 Netvis. All rights reserved.
//
#import "ExceptionHandler.h"
#import <UIKit/UIKit.h>
static ExceptionHandler * _shareExceptionHandler = nil;
@implementation ExceptionHandler
+ (ExceptionHandler *)getInstance
{
if (_shareExceptionHandler == nil) {
_shareExceptionHandler = [ExceptionHandler new];
};
return _shareExceptionHandler;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/*!
* @brief create a handler for exception
*/
- (void)createExceptionHandler
{
NSSetUncaughtExceptionHandler(&exceptionHandler);
struct sigaction mySigAction;
mySigAction.sa_sigaction = exceptionHandlerSpecialSIGNAL;
mySigAction.sa_flags = SA_SIGINFO;
sigemptyset(&mySigAction.sa_mask);
sigaction(SIGQUIT, &mySigAction, NULL);
sigaction(SIGILL, &mySigAction, NULL);
sigaction(SIGTRAP, &mySigAction, NULL);
sigaction(SIGABRT, &mySigAction, NULL);
sigaction(SIGEMT, &mySigAction, NULL);
sigaction(SIGFPE, &mySigAction, NULL);
sigaction(SIGBUS, &mySigAction, NULL);
sigaction(SIGSEGV, &mySigAction, NULL);
sigaction(SIGSYS, &mySigAction, NULL);
sigaction(SIGPIPE, &mySigAction, NULL);
sigaction(SIGALRM, &mySigAction, NULL);
sigaction(SIGXCPU, &mySigAction, NULL);
sigaction(SIGXFSZ, &mySigAction, NULL);
}
void exceptionHandler(NSException * exception)
{
NSArray * stack = [exception callStackSymbols];
NSString * strStack = [stack description];
strStack = [NSString stringWithFormat:@"Reason: %@.\n Callstack: %@",[exception reason],strStack];
NSLog(@"exceptionHandler trace : %@", strStack);
}
void exceptionHandlerSpecialSIGNAL(int sig, siginfo_t *info, void *context) {
/// just can get sig "Signal %@ was raised."
}
@end