IOS captures out-of-system exceptions

Source: Internet
Author: User

IOS captures out-of-system exceptions

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.


Sometimes the application crashes, and the log output information is too small to locate the problem, this is the most headache, especially when it is very tired, has not been able to remember what has just changed, this is called non-resistance.

工欲善其事, its prerequisite, the following method can give more information, let you see the sequence of stack execution, where the collapse, you can probably give a thought to determine the crux of the problem.

Before the APPDELEGATE.M class implementation, add:

void Uncaughtexceptionhandler (NSException *exception) {        //Get exception related information    Nsarray *callstacksymbols = [exception Callstacksymbols];    NSString *callstacksymbolstr = [Callstacksymbols componentsjoinedbystring:@ "\ n"];    NSString *reason = [exception reason];    NSString *name = [exception name];        Gets the current time of the system    nsdate * date = [NSDate date];    NSDateFormatter * Dateformatter = [[NSDateFormatter alloc] init];    [Dateformatter setdateformat:@ "yyyy mm month DD day HH hours mm minutes ss seconds"];    NSString * Datestr = [dateformatter stringfromdate:date];        NSLog (@ "System current time:%@ \ n", datestr);    NSLog (@ "exception name:%@ \ n", name);    NSLog (@ "Exception reason:%@ \ n", reason);    NSLog (@ "stack flag:%@ \ n", callstacksymbolstr);}


In the APPDELEGATE.M class implementation of the application startup method, add the following statement, the system set the exception callback function for the above declaration, detailed description See "IOS Foundation Framework Overview Documentation: constants, data types, frames, functions, publishing declarations":
@implementation appdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {        nssetuncaughtexceptionhandler (&uncaughtexceptionhandler);    



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.