• /
  • ログイン
  • 無料アカウント

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 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 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" ])
}

その他のヘルプ

さらに支援が必要な場合は、これらのサポートと学習リソースを確認してください:

問題を作成するこのページを編集する
Copyright © 2020 New Relic Inc.