2
votes

I'm currently working on a small project in which I'd like to catch crashes using sentry. The project is using the c# implementation for Godot.

Sentry needs to wrap all executing code to catch exceptions.

Is there a general entrypoint where I can place this try/catch block or would I need to add this into every section of the code that is being called by Godot?

Thanks in advance :)

2
Seems more of a question to Godot folks. Does the AppDomain.UnhandledException event fires when there's an error in any of the scripts? Sentry captures that automatically. Otherwise, what's the way to be notified of errors? - Bruno Garcia
In my regular applications I only need to add it to the regular MainWindow method which contains all required calls. - Catmzero
There's a pull request that implements crash reporting into Godot using C++, but it's unlikely to be merged now. - Calinou

2 Answers

2
votes

Once it's set-up, the Sentry C# client attaches itself to some dotnet framework exception hooks, like AppDomain.UnhandledException.

So, you're not required to plant try / catch clauses anywhere.

Just initialize the SentrySDK object like this:

SentrySdk.Init(o => {
    o.Dsn = new Dsn("https://[email protected]/5170198");
});

And the framework should invoke Sentry and create a report on its own.

I recently wrote an article demonstrating just that.

1
votes

I have recently implemented Sentry SDK but AppDomain.UnhandledException doesn't work in Godot C# mono implementation. You have to manually catch unhandled exceptions like this:

SentrySdk.Init(opts => { opts.Dsn = "<sentry dsn url>"; });

GD.UnhandledException += (sender, args) => {
    if (SentrySdk.IsEnabled) {
        SentrySdk.CaptureException(args.Exception);
    }
};

This was added in Godot 3.3+ version https://github.com/godotengine/godot/pull/46174