1. Log

Log: the system or program will record all kinds of data in the process of running the program, we use these data to find problems, solve errors, performance analysis, so logging is essential for a high-performance application.

Buried point: the main function is to analyze user behavior, but also can be used as a record of the scene when problems occur. Buried point path analysis is often used to carry out the user’s behavior, for an electrical business applications app, for example, buy a path there are a lot of goods, from the search module to the commodity purchase, from classification module to find sources of goods to buy, from advertising to buy or friends recommend purchasing, etc., by buried PM records can help run better adjust strategy.

1.1 Anomaly Analysis

Crash is a serious BUG in a program. As follows:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *array = @[@"1",@"2"];
    
    NSLog(@"%@",array[2]);
}
Copy the code

The above code is obviously wrong, the array is out of bounds, the console output Crash message as follows:

2020-10-27 20:57:44.534502+0800 FMDBActions[42334:2120891] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndexedSubscript:]: index 2 beyond bounds [0 .. 1]' *** First throw call stack: ( 0 CoreFoundation 0x00007fff23e3cf0e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23ecfa51 _CFThrowFormattedException + 194 3 CoreFoundation 0x00007fff23eae9bd -[__NSArrayI objectAtIndexedSubscript:] + 93 4 FMDBActions 0x0000000103c8406f -[ViewController viewDidLoad] + 159 5 UIKitCore 0x00007fff485dbac2 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83 6 UIKitCore 0x00007fff485e09e0 -[UIViewController loadViewIfRequired] + 1084 7 UIKitCore 0x00007fff48545480 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 160 8 UIKitCore 0x00007fff48545781 -[UINavigationController _startTransition:fromViewController:toViewController:] + 141 9 UIKitCore 0x00007fff4854660f -[UINavigationController _startDeferredTransitionIfNeeded:] + 868 10 UIKitCore 0x00007fff48547954 -[UINavigationController __viewWillLayoutSubviews] + 150 11 UIKitCore 0x00007fff48528924 -[UILayoutContainerView layoutSubviews] + 217 12 UIKitCore 0x00007fff49193678 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478 13 QuartzCore 0x00007fff2b4c6398 -[CALayer layoutSublayers] + 255 14 QuartzCore 0x00007fff2b4cc523 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 523 15 QuartzCore 0x00007fff2b4d7bba _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80 16 QuartzCore 0x00007fff2b420c04 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324 17 QuartzCore 0x00007fff2b4545ef _ZN2CA11Transaction6commitEv + 649 18 UIKitCore 0x00007fff48ca3747 __34-[UIApplication _firstCommitBlock]_block_invoke_2  + 81 19 CoreFoundation 0x00007fff23da0b5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 20 CoreFoundation 0x00007fff23da0253 __CFRunLoopDoBlocks + 195 21 CoreFoundation 0x00007fff23d9b043 __CFRunLoopRun + 995 22 CoreFoundation  0x00007fff23d9a944 CFRunLoopRunSpecific + 404 23 GraphicsServices 0x00007fff38ba6c1a GSEventRunModal + 139 24 UIKitCore  0x00007fff48c8b9ec UIApplicationMain + 1605 25 FMDBActions 0x0000000103c85732 main + 114 26 libdyld.dylib 0x00007fff51a231fd start + 1 27 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSExceptionCopy the code

You can see a wealth of information, including the exception type, the object and function where the exception occurred, and the complete call stack information.

For Crash problems occurred during the development process, we can directly see the log in Xcode, can be solved according to the log. However, developers can register exception handlers to catch exceptions during user usage.

When starting the application, you can register the following exception catching functions with the system: