sentry-unity icon indicating copy to clipboard operation
sentry-unity copied to clipboard

`Unhandled` exceptions cause sessions to be marked as `crashed`

Open WeiLingQiang opened this issue 1 year ago • 10 comments
trafficstars

          ![image](https://github.com/getsentry/sentry-unity/assets/103353466/270f6162-aae1-423f-84f4-1c585d905480)

There is an error: I throw an exception: throw new InvalidOperationException("xxx") It is considered a crashed, Shouldn't it be an errored ?

Originally posted by @WeiLingQiang in https://github.com/getsentry/sentry-unity/issues/1707#issuecomment-2220051502

WeiLingQiang avatar Jul 10 '24 09:07 WeiLingQiang

          ![image](https://github.com/getsentry/sentry-unity/assets/103353466/270f6162-aae1-423f-84f4-1c585d905480)

There is an error: I throw an exception: throw new InvalidOperationException("xxx") It is considered a crashed, Shouldn't it be an errored ?

Originally posted by @WeiLingQiang in #1707 (comment)

image

WeiLingQiang avatar Jul 10 '24 09:07 WeiLingQiang

Good catch! The SDK considers sessions that had unhandled exceptions happen as crashed as opposed to errored right now. But I get that within the context of a Unity game where Unity prevents the game from actually crashing based on an exception, this might be confusing.

bitsandfoxes avatar Jul 11 '24 12:07 bitsandfoxes

Thanks, What should I do if I want to count actual crashes in Unity games? And count the crash rate

WeiLingQiang avatar Jul 12 '24 01:07 WeiLingQiang

had unhandled exceptions happen

Because an unhandled exception occurs, the game will not actually crash

WeiLingQiang avatar Jul 12 '24 02:07 WeiLingQiang

What the SDK could do is to add to the mechanism type to basically filter exceptions. The only workaround for you, to unblock yourself, that I can see right now is to set the Exception.Data[Mechanism.HandledKey] = true in the BeforeSend callback.

bitsandfoxes avatar Jul 15 '24 16:07 bitsandfoxes

For what it's worth, we've had a very long discussion about resolving this (indirectly) in an RCF.

bitsandfoxes avatar Jul 15 '24 16:07 bitsandfoxes

Excuse me, is there a solution?

What the SDK could do is to add to the mechanism type to basically filter exceptions. The only workaround for you, to unblock yourself, that I can see right now is to set the Exception.Data[Mechanism.HandledKey] = true in the BeforeSend callback.

options.SetBeforeSend((sentryEvent, _) => {
    if (sentryEvent.Exception != null) {
        sentryEvent.Exception.SetSentryMechanism("error", "UnityException", true);
        sentryEvent.Exception.Data[Mechanism.HandledKey] = true;
    }
    return sentryEvent;
});

I set BeforeSend but it still doesn't work, help me !

WeiLingQiang avatar Jul 17 '24 03:07 WeiLingQiang

image

WeiLingQiang avatar Jul 17 '24 03:07 WeiLingQiang

Apologies for the delay. The mechanism is not the one on the actual exception-object but on the SentryException. Again, I don't recommend doing it that way but if you've got a valid usecase then it could look like this:

options.SetBeforeSend((sentryEvent, _) => {
    if (sentryEvent.Exception != null) {
        sentryEvent.SentryExceptions.FirstOrDefault().Mechanism.Handled = true;
    }
    return sentryEvent;
});

bitsandfoxes avatar Jul 29 '24 13:07 bitsandfoxes

Thanks, this helps me

WeiLingQiang avatar Jul 30 '24 03:07 WeiLingQiang

Resolved by #2376

bitsandfoxes avatar Nov 06 '25 19:11 bitsandfoxes