This document describes a legacy version of the iOS SDK. If your new to Analyitcs, use the latest SDK. Learn more

Crashes & Exceptions - iOS SDK

This document provides a high-level overview of crash and exception measurement using the Google Analytics SDK for iOS v2.


Crash and exception measurement allows you to measure the number and type of crashes and exceptions that occur in your app. An exception in Google Analytics consists of:

  • NSString (Optional) Description – a description of the exception (up to 100 characters). Accepts nil.
  • boolean isFatal – indicates whether the exception was fatal. YES indicates fatal.

Crash and exception data is available primarily in the Crash and Exceptions report.

Caught Exceptions

Caught exceptions are errors in your app for which you've defined exception handling code. These are generally errors you would anticipate to occur during normal use of your app, and from which you'd like your app to be able to recover, such as the occasional timeout of a network connection during a request for data.

You can measure caught exceptions by adding sendException: to the catch block of your exception handling code.

In the following example, an app tries to load a list of high scores from the cloud. If the request times out, perhaps due to a slow network connection, we'll send the exception to Google Analytics before handling it for the user:

@try {
  NSArray *highScores = [self getHighScores];
@catch (NSException *exception) {
    [tracker sendException:NO // Boolean indicates non-fatal exception.
            withDescription:@"Connection timout %d: %@", connectionError, errorDescription];

You can automatically populate the description field of an exception with the name and reason by using sendException:withDescription:withNSException:, as in this example:

@try {
  NSArray *highScores = [self getHighScores];
@catch (NSException *exception) {
  [tracker sendException:NO withNSException:exception);

To automatically populate an error with the error domain, code, and description, use sendException:withDescription:withNSError: as seen below:

NSError *error = nil;
if (![self updateHighScoresWithError:&error]) {
  [tracker sendException:NO withNSError:error);

Uncaught Exception Measurement

Uncaught exceptions represent instances where your app encountered unexpected conditions at runtime and are often fatal, causing the app to crash as a result. Uncaught exceptions can be sent to Google Analytics automatically by setting the sendUncaughtExceptions property to YES. This can be done conveniently from your app delegate's application:didFinishLaunchingWithOptions method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GAI sharedInstance].sendUncaughtExceptions = YES; // Enable 

  // ... the rest of your code, include other GAI properties you want to set.

When using automatic exception measurement, keep in mind the following:

  • All exceptions sent using automatic exception measurement are reported as fatal in Google Analytics.
  • The description field is automatically populated using the stack trace.