Report Errors and Exceptions
The domain: String used to initialize the standard NSError object used for reportError should not use unique string such as Hashes, StackTraceID or ThreadID. Including those will create an infinite number of Error Group which will impact performance.
To add unique error strings and values, you have two data collection options:
- Add a string value as a breadcrumb. If the event/error, you are reporting has a single value attached, add the value to leaveBreadcrumb. See Breadcrumbs
- Add string name and integer values. If the event/error, you are reporting has both name and integer values attached, add the values to
reportMetricWithName. See Custom Metrics.
You can report exceptions using the method reportError from the ADEumInstrumentation class. Reported exceptions will appear in session details.
The method can have the following two signatures:
| Objective-C Function Signature | Description |
|---|---|
(void)reportError:(NSError *)error withSeverity (ADEumErrorSeverityLevel)severity; |
Use this signature to report errors, set the severity level of the issue, and send the stack trace. This function signature sends the stack trace by default. If you don't want to send the stack trace, use the function signature below with the additional argument and StackTrace and set its value to NO. Warning: The
domain: String used to initialize the standard NSError object used for reportError should not use unique string such as Hashes, StackTraceID or ThreadID. Including those will create an infinite number of Error Group which will impact performance.To add unique error strings and values, you have two data collection options:
|
(void)reportError:(NSError *)error withSeverity:(ADEumErrorSeverityLevel)severity andStackTrace:(BOOL)stacktrace; |
Use this signature to report errors, set the severity level of the issue, and explicitly specify whether the stack trace should be included. If you include the stack trace with the reported error by setting stacktrace to YES, you can view the stack trace in the Code Issues Details dialog. To report the error without the stack trace, set stacktrace to NO. Warning: The string message used to construct a new throwable used for reportError should not use unique string such as hashes, StackTraceID or ThreadID. Including those will create an infinite number of Error Group which will impact performance.
To add unique error strings and values, you have two data collection options:
|
Severity Levels
You can also set one of the following severity levels for an issue. With the severity level, you can filter errors in the Code Issues Dashboard or Code Issues Analyze.
-
ADEumErrorSeverityLevelInfo -
ADEumErrorSeverityLevelWarning -
ADEumErrorSeverityLevelCritical
Examples of Reporting Errors
ADEumErrorSeverityLevelCritical for a failed attempt to perform a file operation: - Objective-C
-
NSError *err = nil; [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"pathToFile" error:&err]; if (err) { [ADEumInstrumentation reportError:err withSeverity:ADEumErrorSeverityLevelCritical, andStackTrace: NO]; } else { ... } - Swift
-
var err: Error? = nil try? FileManager.default.contentsOfDirectory(atPath: "pathToFile") if err != nil { ADEumInstrumentation.reportError(err, withSeverity: ADEumErrorSeverityLevelCritical, andStackTrace: false) } else { ... }
domain: String used to initialize the standard NSError object used for reportError should not use unique string such as Hashes, StackTraceID or ThreadID. Including those will create an infinite number of Error Group which will impact performance.To add unique error strings and values, you have two data collection options:
- Add a string value as a breadcrumb. If the event/error, you are reporting has a single value attached, add the value to leaveBreadcrumb. See Breadcrumbs.
- Add string name and integer values. If the event/error, you are reporting has both name and integer values attached, add the values to reportMetricWithName. See Custom Metrics.
- Objective-C
-
NSString *domain = @"com.YourCompany.AddUsers.ErrorDomain"; NSString *desc = NSLocalizedString(@"Unable to add user.", @""); NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : desc }; NSError *error = [NSError errorWithDomain:domain code:-101 userInfo:userInfo]; [ADEumInstrumentation reportError:error withSeverity: ADEumErrorSeverityLevelWarning]; - Swift
-
var domain = "com.YourCompany.AddUsers.ErrorDomain" var desc = NSLocalizedString("Unable to add user.", comment: "") var userInfo = [NSLocalizedDescriptionKey: desc] var error = NSError(domain: domain, code: -101, userInfo: userInfo) ADEumInstrumentation.reportError(error, withSeverity: ADEumErrorSeverityLevelWarning)