Replies: 1 comment
-
I can't reproduces the unhandled exception: static void Main(string[] args)
{
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
Console.WriteLine($"Entrance thread id: {Thread.CurrentThread.ManagedThreadId}");
Method();
AppDomain.CurrentDomain.UnhandledException += (s, e) => Console.WriteLine("Unhandled exception!");
Dispatcher.Run();
}
static async void Method()
{
try
{
await Task.Delay(1000).ConfigureAwait(true);
Console.WriteLine($"Resumed thread id: {Thread.CurrentThread.ManagedThreadId}");
throw new Exception();
}
catch
{
Console.WriteLine("Caught!");
}
} Prints:
The exception is dispatched by the ChatGPT should be saying about that exceptions can't be handled by the In the documentation about
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In MAUI I recieved an exception report which says there would have been an unhandled exception in an
async void
method. This method looks like this:and its called from UI thread like this:
_ = Method();
I'd expect that any .NET exception, especially null exception would be handled by the
try-catch
block. When I ask ChatGPT, it answered:async void Methods:
It suggested me to change it to
async Task
because:When an async Task method throws, the exception is stored inside the Task object
. I did not know that. Is that true? And if that is true, it would be a wonderful idea if there was a warning in VS that exceptions in myasync void
may not be handled by thetry catch
block? Can such a warning be added please?Beta Was this translation helpful? Give feedback.
All reactions