using System;
using System.Runtime.ExceptionServices;
using Avalonia.MicroCom;
using Avalonia.Platform;

namespace Avalonia.Native
{
    public abstract class NativeCallbackBase : CallbackBase, IMicroComExceptionCallback
    {
        public void RaiseException(Exception e)
        {
            if (AvaloniaLocator.Current.GetService<IPlatformThreadingInterface>() is PlatformThreadingInterface threadingInterface)
            {
                threadingInterface.TerminateNativeApp();

                threadingInterface.DispatchException(ExceptionDispatchInfo.Capture(e));
            }
        }
    }
}
