Cocoa - reporting custom errors

Is there a way in the Cocoa SDK to report custom errors which didn’t reach the main exception handler - e.g. if a service or API I use returns an NSError with some failure codes and messages, or I catch a Swift Error object in a do/try/catch block? Is client.send(event:) meant for such use cases? If I pass the NSError info there and call snapshotStacktrace, will this be added as an entry on my “Issues” list on just like if it was a fatal exception?

Yes, of course, I would take this as guidance

you can set every property on the event.
You could also create an event without the snapshotStacktrace method depending on your needs.

Ok, I’ve tried it now - I’m getting a report, but the stack trace isn’t being sent:

Here’s my code:

func applicationDidFinishLaunching(_ aNotification: Notification) {
    // Create a Sentry client and start crash handler
    do {
        Client.shared = try Client(dsn: "...")
        try Client.shared?.startCrashHandler()
    } catch let error {
        // Wrong DSN or KSCrash not installed

    Client.shared?.snapshotStacktrace {
        let event = Event(level: .warning)
        event.message = "API call failed: incorrect image size"
        event.environment = "debug"

        Client.shared?.appendStacktrace(to: event)
        Client.shared?.send(event: event)

Sample project:

The effect is the same when I log the error from some other place, e.g. after pressing a button, and in an iOS app.

Oh, @mackuba that must be a bug, I will look into this now.

I’ve released 3.7.1 which fixes this error.

1 Like

Wow, you guys are unbelievable :slight_smile: Just tested 3.7.1, looks like it’s working :+1:

1 Like

Hello, I have tried:

    SentryEvent* event = [[SentryEvent alloc] initWithLevel:kSentrySeverityFatal];
    [event setMessage:[exception reason]];
    [SentryClient.sharedClient appendStacktraceToEvent:event];
    [SentryClient.sharedClient sendEvent:event withCompletionHandler:nil];

but unfortunately there is no stack trace on the web UI.