Exception Analysis
Set Breadcrumb
Developers can call the "breadcrumb" API at any location in the application for instrumentation. When the application crashes, the SDK will collect the breadcrumb information in the order of code execution and highlight it in the crash trace, helping developers understand the code call logic when the application crashes.
- Related API
/**
* @breadcrumb: Custom information, up to 100 characters, supports Chinese, English, numbers, underscores
*/
+(void)leaveBreadcrumb:(NSString *)breadcrumb;
- Code Example
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOption:(NSDictionary *)launchOptions
{
// Set breadcrumb
[NBSAppAgent leaveBreadcrumb:@"didFinishLaunchingWithOptions"];
return YES;
}
Custom Information
When an application crashes, developers often need more information to collect the scene environment. You can upload additional information by calling the "custom information" API to assist in analyzing crash issues. The collected custom information will be displayed in the "Custom Information" section of the exception details page.
- Related API
/**
* This function can be called multiple times at any location, up to 10 additional information entries can be added. Each entry supports up to 100 bytes, uploaded with the crash.
*/
+(void)setCustomerData:(NSString*)data forKey:(NSString*)key;
- Code Example
- (void)doSomething
{
[NBSAppAgent setCustomerData:@"value" forKey:@"key"];
...
}
Custom Error
Using the "custom error" API, you can collect developers' "try / catch exceptions" and "business errors" and display them in the Tingyun platform's "Exception Analysis → Errors" section, helping developers collect exceptions and errors.
- Related API
/**
* Parameter description:
* @message: Cannot be empty, maximum length 1024 bytes, truncated to the first 1024 bytes if exceeded
* @exception: Upload exception to get the stack at the time of throw. If not provided, only the stack of the calling API is obtained. In multithreading, only the stack of the calling API's thread is obtained. Maximum stack depth is 100.
* @metaData: value supports NSNumber, NSString, NSArray, NSDictionary types, maximum 128k. If exceeded, metadata will be: "metaData":{"error":"metaData size exceeds the maximum limit of 128K"}
*/
+ (void)reportError:(NSString *)message withMetaData:(NSDictionary *)metaData;
+ (void)reportError:(NSString *)message withException:(NSException *)exception withMetaData:(NSDictionary *)metaData;
- Code Example
- (void)doSomething
{
...
if(success){
...
}else{
NSDictionary *dict = @{@"k1":@"v1",@"K2":@"V2"};
[NBSAppAgent reportError:@"errorMsg" withMetaData:dict];
}
...
}
- (void)doSomething
{
@try {
// ... do something that might throw an exception ...
}
@catch (NSException *exception) {
// report the error
NSDictionary *dict = @{@"k1":@"v1",@"K2":@"V2"};
[NBSAppAgent reportError:@"errorMsg" withException:exception withMetaData:dict];
}
@finally {
}
...
}
Set Crash Type Collection
If you do not need to collect certain signal types of errors, you can call this API to ignore them. Supports ignoring single or multiple types.
- Related API
/**
* Signals supported by the SDK:
* SIGABRT, //6
* SIGBUS, //10
* SIGFPE, //8
* SIGILL, //4
* SIGSEGV, //11
* SIGSYS, //12
* SIGTRAP, //5
* SIGKILL,//9
* @ignore Parameter supports string, NSNumber, NSArray
*/
+ (void)ignoreSomeSignalCrash:(id)ignore;
- Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
// Call before initialization
[NBSAppAgent ignoreSomeSignalCrash:@"SIGABRT"];
[NBSAppAgent startWithAppID:@"appkey" location:YES];
...
}
}
Set Exception Callback
After using the "exception callback" API, you can obtain the exception data collected by the SDK (crash, ANR) when a crash or ANR occurs. Note: You need to call this before crash upload or ANR occurs. After the SDK successfully connects to the server, crash data will be uploaded.
- Related API
/**
* @brief Set custom callback when crash or ANR occurs
* @type Value is NBSCallBackOnCrash or NBSCallBackOnANR
*/
+ (void)setCallBack:(NBSCallBack)callback withType:(NBSCallBackType)type;
- Code Example
- (void)getExceptionInfo
{
// context is the context information of crash or ANR collected by the SDK
[NBSAppAgent setCallBack:^(NSDictionary *context) {
...
} withType:NBSCallBackOnCrash];
}
Set Jailbreak Devices Not to Collect Crash/ANR
After calling this API, crash and ANR information will no longer be collected on jailbroken devices.
- Related API
/**
* @brief Do not collect crash and ANR data on jailbroken devices. Call before SDK start.
*/
+ (void)disableJailbreakExceptionDataCollection;
- Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
// Call before initialization
[NBSAppAgent disableJailbreakExceptionDataCollection];
[NBSAppAgent startWithAppID:@"appkey" location:YES];
...
}
}