I want to test my app\'s crash reporting out in the field by deliberately having it crash when the user performs a particular action that a real user is unlikely to do accid
abort();
causes abnormal termination… That is a crash.
I use
[self doesNotRecognizeSelector:_cmd];
in Objective-C use C directly to cause a bad access
strcpy(0, "bla");
Note: while this works on any system I know -- in a future version of the C runtime OR the compiler this might not lead to a crash anymore. see Is null pointer dereference undefined behavior in Objective-C?)
(in swift you would have to bridge to objC to do this)
I would just kill the process normally:
kill(getpid(), SIGKILL);
So if you install a handler with signal you can also handle the crash, finishing to write opened files and these things.
Try this:
- (IBAction)Button:(id)sender
{
NSArray *array = [NSArray new];
NSLog(@"%@",[array objectAtIndex:8]);
}
Most popular one - unrecognised selector crash:
NSObject *object = [[NSObject alloc] init];
[object performSelector:@selector(asfd)];
Make sure you don't have -asdf method implemented in that class haha
Or index beyond bound exception:
NSArray * array = [NSArray array];
[array objectAtIndex:5];
And of course
kill( getpid(), SIGABRT );