Syntax
recordError:(NSError* _Nonnull)error attributes:(NSDictionary* _Nullable)attributes;NewRelic.recordError(error: $Error, map $eventAttributes);
Records Swift errors and NSErrors as MobileHandledException events. Optionally takes map with additional attributes showing context.
Requirements
Agent version 6.0.0 or higher.
Description
You can use the recordError
API call for crash analysis. Review the captured events to help you understand how often your app is throwing errors and under what conditions. In addition to any custom attributes that you added, the events will also have associated session attributes.
This API takes an instance of an NSError
and an optional NSDictionary
attribute dictionary, then creates a recordHandledException
event. You can view event data both in Insights and in the New Relic Mobile UI, including the Handled exceptions page and the Crash events trail.
For context on how to use this API, see the documentation about sending custom attributes and events to Insights for:
Parameters
Parameter | Description |
---|---|
NSError, Error | Required. The error object that was thrown. |
NSDictionary, [AnyHashable, Any]? | Optional. Dictionary of attributes that give context. |
Return values
Returns true
if the error was recorded successfully, or false
if not.
Examples
Objective-C
Method:
+ (void) recordError:(NSError* _Nonnull)error attributes:(NSDictionary* _Nullable)attributes;+ (void) recordError:(NSError* _Nonnull)error;
Examples:
Simple Objective-C example:
[NSJSONSerialization JSONObjectWithData:data options:opt error:error];if (error) { [NewRelic recordError:error];}
Objective-C example with dictionary:
[NSJSONSerialization JSONObjectWithData:data options:opt error:error];if (error) { [NewRelic recordError:error withAttributes:@{@"int": @1, @"Test Group" : @"A | B"}];}
Swift
Method:
func recordError(error: Error)func recordError(error: Error, attributes: [ AnyHashable : Any]?)
Examples:
Simple Swift example:
do { try method()} catch { NewRelic.recordError(error)}
Swift example with dictionary:
do { try method()} catch { NewRelic.recordError(error, attributes: [ "int" : 1, "Test Group" : "A | B" ])}
For more help
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.