Syntax
recordHandledException:(NSException* __nonnull)exception withAttributes:(NSDictionary* __nullable)attributes;
Records a handled exception. Optionally takes map with additional attributes showing context.
Requirements
Agent version 5.15.0 or higher.
Description
The recordHandledException
API is useful for crash analysis; the captured events will help you understand how often your application is throwing exceptions and under what conditions. In addition to associated custom attributes, the events will also have associated session attributes.
This API takes an instance of an NSException
and an optional NSDictionary
attribute dictionary, then creates a recordHandledException
event. You can view event data in the Crash event trail UI, and query them with NRQL.
For context on how to use this API, see the documentation about sending custom attributes and events:
Important
This fuction should not be used with Swift code. Please use recordError to track handled errors in Swift code.
Parameters
Parameter | Description |
---|---|
NSException | Required. The exception object that was thrown. |
NSDictionary | Optional. Dictionary of attributes that give context. |
Examples
Objective-C
Method:
+ (void) recordHandledException:(NSException* __nonnull)exception withAttributes:(NSDictionary* __nullable)attributes;
+ (void) recordHandledException:(NSException* __nonnull)exception;
Examples:
Simple Objective-C example:
@try { @throw [NSException exceptionWithName:@"versionException" reason:@"App version no longer supported" userInfo:nil]; } @catch (NSException* e) { [NewRelic recordHandledException:e]; }
Objective-C example with dictionary:
NSException *exception = [NSException exceptionWithName:@"MyException" reason:@"I have my reason" userInfo:nil]; NSDictionary* dictionary = @{@"int": @1, @"Test Group" : @"A | B"}; [NewRelic recordHandledException:exception withAttributes:dictionary];