recordError

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

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

$error

NSError, Error

Required. The error object that was thrown.

$attributes​

NSDictionary, [AnyHashable, Any]?

Optional. Dictionary of attributes that give context.

Return value(s)

Returns true if the error was recorded successfully, or false if not.

Example(s)

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

Recommendations for learning more: