sentry-unity
sentry-unity copied to clipboard
`Unhandled` exceptions cause sessions to be marked as `crashed`

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
There is an error: I throw an exception:
throw new InvalidOperationException("xxx")It is considered acrashed, Shouldn't it be anerrored?Originally posted by @WeiLingQiang in #1707 (comment)
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.
Thanks, What should I do if I want to count actual crashes in Unity games? And count the crash rate
had unhandled exceptions happen
Because an unhandled exception occurs, the game will not actually crash
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.
For what it's worth, we've had a very long discussion about resolving this (indirectly) in an RCF.
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] = truein theBeforeSendcallback.
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 !
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;
});
Thanks, this helps me
Resolved by #2376