forked from sascha/godot
C#: Re-introduce exception logging and error stack traces in editor
These two had been disabled while moving to .NET 5, as the previous implementation relied on Mono embedding APIs.4.0
parent
67db89988d
commit
778007a358
@ -1,17 +1,33 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Godot.NativeInterop;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
public static partial class GD
|
||||
{
|
||||
/// <summary>
|
||||
/// Fires when an unhandled exception occurs, regardless of project settings.
|
||||
/// </summary>
|
||||
public static event EventHandler<UnhandledExceptionArgs> UnhandledException;
|
||||
|
||||
private static void OnUnhandledException(Exception e)
|
||||
[UnmanagedCallersOnly]
|
||||
internal static void OnCoreApiAssemblyLoaded(godot_bool isDebug)
|
||||
{
|
||||
UnhandledException?.Invoke(null, new UnhandledExceptionArgs(e));
|
||||
try
|
||||
{
|
||||
Dispatcher.InitializeDefaultGodotTaskScheduler();
|
||||
|
||||
if (isDebug.ToBool())
|
||||
{
|
||||
DebuggingUtils.InstallTraceListener();
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
|
||||
{
|
||||
// Exception.ToString() includes the inner exception
|
||||
ExceptionUtils.LogUnhandledException((Exception)e.ExceptionObject);
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExceptionUtils.LogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
/// <summary>
|
||||
/// Event arguments for when unhandled exceptions occur.
|
||||
/// </summary>
|
||||
public class UnhandledExceptionArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception object.
|
||||
/// </summary>
|
||||
public Exception Exception { get; private set; }
|
||||
|
||||
internal UnhandledExceptionArgs(Exception exception)
|
||||
{
|
||||
Exception = exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue