Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Error in Task that is wrapped as IResult just quietly dies on exception

Open AndersMalmgren opened this issue 2 years ago • 1 comments

Thansk to this code in TaskResult class the Coroutine just queitly dies when exception occours in Task.

        protected virtual void OnCompleted(Task task)
        {
            Completed(this, new ResultCompletionEventArgs { WasCancelled = task.IsCanceled, Error = task.Exception });
        }

OnUnhandledException in bootstrapper isnt called either

AndersMalmgren avatar Jun 22 '23 13:06 AndersMalmgren

A workaround to catch unhandled exceptions is to use the Coroutine.Completed event.

public abstract class TypedBootstrapper : BootstrapperBase
{
    protected override void Configure()
    {
        Coroutine.Completed += CoroutineOnCompleted;
    }

    private static void CoroutineOnCompleted(object sender, ResultCompletionEventArgs e)
    {
        if (e.Error != null)
        {
            // Do something with the unhandled exception
        }
    }
}

darxis avatar Oct 16 '24 18:10 darxis