• /
  • Log in
  • Free account

recordError (iOS SDK API)

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 in the mobile monitoring UI in places like the Handled exceptions page and the Crash events trail. You can also query this data with NRQL, and chart it in New Relic One dashboards.

For context on how to use this API, see the documentation about sending custom attributes and events:

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 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" ])
}
Create issueEdit page
Copyright © 2022 New Relic Inc.