How to catch EXC_BAD_ACCESS (code=1, address=0x00XXXXXX)?
You can refer the following links :
EXC_BAD_ACCESS automatic handling
Also look into this :
How to prevent EXC_BAD_ACCESS from crashing an app?
Related videos on Youtube
Suran
Updated on September 14, 2022Comments
-
Suran over 1 year
I'm trying to log all the crashes that are occurring in my app. I've written a signalHandler and an exceptionHandler. I'm registering the signalHandler for all the signals that are defined in sys/signal.h file. And I'm getting my signalHandler method invoked on SIGABRT, SIGUSR1, etc..
The problem is that, I'm getting some weird signals at times, that are not invoking my signalHandler. One example is EXC_BAD_ACCESS (code=1 or 2, address='some memory address'). I've registered SIGSEGV with the signalHandler; in fact I've registered all the defined signals in sys/signal.h file.
If you want to create this EXC_BAD_ACCESS (code=1, address=0x00XXXXXX)signal, just write the following line of code in your app,
NSLog(@"Stupid Log %@ %@");
Can someone please help me, to catch such signals?
Thanks in advance,
Suraj
-
Admin about 11 yearsI don't think you can catch a segmentation fault. When it occurs, your program has messed up something in the memory so seriously that it doesn't have a chance to be resumed, the only thing can be done is that the OS kills the process. Try writing good code without memory management mistakes instead, that's way more powerful and elegant.
-
Suran about 11 years@H2CO3, I understand that, the best thing to do is to write good code without memory management mistakes. But, as you know, everyone makes some mistakes; in my case, I make a hell lot of mistakes. It'll be really good, to have a back up plan like, logging all the crashes, in case we make some terrible memory management mistakes. So is this signal coming because of segmentation fault?
-
Suran about 11 years@H2CO3, The signal SIGSEGV means segmentation fault right?, And we can handle SIGSEGV signals. But, only EXC_BAD_ACCESS with this 'code' in parentheses are not getting caught. Any idea, why is that? Can you please help me understand it properly?
-
Admin about 11 years@Suran "we can handle SIGSEGV signals" - for the reasons I just explained, you can't. And
EXC_BAD_ACCESS
is not a signal, it's the name of the error code your process (or rather the OS) throws when the segfault occurs. -
Suran about 11 years@H2CO3, What I meant is that, we can invoke a method/signalHandler on EXC_BAD_ACCESS error aka SIGSEGV signal. And we can do that. The problem I was having was because, the device was connected to GDB. When I run the app, disconnected from XCode/Mac, the signalHandler is working fine and is giving me logs. Anyway, thanks for the help...:-)
-
Admin about 11 years@Suran I understood what you meant, and you can't, because
EXC_BAD_ACESS
is not a signal name. -
Suran about 11 years@H2CO3 I never said that EXC_BAD_ACCESS is a signal. Sorry, if I caused you any confusion.
-
-
Suran about 11 yearsActually, I'm trying to find a way to handle the EXC_BAD_ACCESS (code=1,...) crash. The NSLog I provided is just to create such a crash.
-
V-Xtreme about 11 years@Suran:Sorry , I misread the question. Have referred this :stackoverflow.com/questions/10315526/… and stackoverflow.com/questions/15513864/…
-
Suran about 11 yearsThanks, The first link helped. The signalHandler is getting called when I'm running the app, after disconnecting the device from XCode/Mac. Please edit your answer to include the links, I'll accept the answer.
-
V-Xtreme about 11 years@Suran:its nice to hear that it helped you .