Skip to content

Better exception handling for systems and observers. #92

Open
@BeanCheeseBurrito

Description

@BeanCheeseBurrito

In .NET 9, exceptions thrown inside systems cause the app to terminate with no stack trace. Exceptions can also no longer be caught with a debugger. This can be fixed by setting the DOTNET_LegacyExceptionHandling environment variable to use the old exception handler. Setting an environment variable is not always convenient, so we need to figure out a way to get stacktraces logged.

var system = world.System()
    .Each(static (Iter it, int i) =>
    {
        throw new Exception();
    });

system.Run();

DOTNET_LegacyExceptionHandling=0 (New exception handling)

terminate called after throwing an instance of 'PAL_SEHException'

DOTNET_LegacyExceptionHandling=1 (Old exception handling)

Unhandled exception. System.Exception: Exception of type 'System.Exception' was thrown.
   at Playground.<>c.<Main>b__2_0(Iter it, Int32 i) in /_/Flecs.NET/src/Flecs.NET.Examples/Playground.cs:line 48
   at Flecs.NET.Core.Invokers.EachIterCallbackDelegate.Invoke[TFieldGetter](Fields& fields, Int32 count, InvokerCallback callback) in /_/Flecs.NET/src/Flecs.NET/Generated/Invoker/Each/T0.g.cs:line 66
   at Flecs.NET.Core.Invokers.EachIterCallbackDelegate.Flecs.NET.Core.Invokers.IEachInvoker.Invoke[TFieldGetter](Fields& fieldData, Int32 count, InvokerCallback callback)
   at Flecs.NET.Core.Invoker`16.Each[TInvoker](Iter it, InvokerCallback callback) in /_/Flecs.NET/src/Flecs.NET/Core/Invoker.cs:line 113
   at Flecs.NET.Core.BindingContext.Functions.EachIterCallbackDelegate(ecs_iter_t* iter) in /_/Flecs.NET/src/Flecs.NET/Generated/BindingContext/Each/T0.g.cs:line 26
   at Flecs.NET.Core.BindingContext.Functions.IteratorCallback(ecs_iter_t* iter) in /_/Flecs.NET/src/Flecs.NET/Core/BindingContext/Functions.cs:line 74

In the long term, I'd like to implement a managed version of World.Progress() that'll move system execution to C# instead of letting flecs handle it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions