Skip to main content

Handling error

Make great use of error handling and document these errors.

Introduction

Shake allows you to report those caught errors and group them together. These non-fatal error reports will have all of the same contextual information as crash reports and will act as an extension to the crash reporting feature.

note

Avoid using unique values for error clusterID as that would cause a large number of reported errors to stay unrelated and ungrouped, which would clog your Shake dashboard.

ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
do {
try functionThatCanThrowError()
} catch let error {
Shake.handleError(error, clusterID: "MyViewController")
}
}
private func functionThatCanThrowError() throws {
throw MyError.testError
}

Error structure

The handleError function will accept NSError types which naturally contain the following properties:

  • code: Int
  • domain: String
  • userInfo: [AnyHashable : Any]? = nil

Caught exceptions

Shake doesn't provide an interface to directly report caught NSExceptions.

Cocoa APIs are not exception safe, and should be treated as a developer error which terminates the program shortly after.

Although the NSException can be caught by using the @catch statement, this is considered a bad practice and shouldn't be done anywhere in your code.