iOS Dev-Capture program crash log

Source: Internet
Author: User

It is normal to encounter a program crash in iOS development, how to catch the exception information when the program crashes and notify the developer?

Here's how to do this in iOS:

1. Add an exception capture listener during program startup to handle callback actions when the program crashes

1 NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);

Official Document Description: Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.
Uncaughtexceptionhandler is a function pointer that needs to be implemented and can take the name we want. When a program crashes abnormally, the function is called, which is the same concept as the callback function in c,c++.

2. Implement your own processing functions

1234567 voidUncaughtExceptionHandler(NSException*exception) {    NSArray*arr = [exception callStackSymbols];//得到当前调用栈信息    NSString*reason = [exception reason];//非常重要,就是崩溃的原因    NSString*name = [exception name];//异常类型       NSLog(@"exception type : %@ \n crash reason : %@ \n call stack info : %@", name, reason, arr);}

The above code is very simple, but the effect is very large.

iOS Dev-Capture program crash log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.