on async Main, unhandled exception unregisters before capturing crash
See original GitHub issuestatic void Main(string[] args)
{
using var _ = SentrySdk.Init();
throw null;
}
This exception is captured as expected by the unhandled exception handler.
static async Task Main(string[] args)
{
using var _ = SentrySdk.Init();
throw null;
}
The code above doesn’t work as expected. Before calling the UnhandledException
handler the SDK goes out of the using
“block” and unregisters the unhandled exception integration.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10 (9 by maintainers)
Top Results From Across the Web
c# - Async method exception crashing application
I run this inside a try-catch block but - with JustMyCode disabled - I get an error originating from somewhere inside the third...
Read more >Bug - async and uncaught Exceptions
Hello everyone, In one of the projects I'm working on, we're using async and await in order to execute code asynchronously.
Read more >Sentry/CHANGELOG and Sentry Releases (Page 8) | LibHunt
Update unobserved task exception integration (#2034) ... On async Main, dont unregister unhandled exception before capturing crash (#321) ...
Read more >Async Await crash on iOS14 with Xcode 13.2.1 - Compiler
I am observing a crash on iOS14 device when I am using the new concurrency model in Xcode 13.2.1 which is backward compatible....
Read more >Defining Asynchronous JavaScript Code
catch (function(err) { // err will contain an Error object, either due to an unhandled error or to $reject(...) having been called $parameters.Success...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This doesn’t look like a bug in sentry, but more like an expected behavior due to misuse of
async
. When you addasync
modifier to the method, thethrow
expression changes meaning. Instead of throwing an exception immediately on the stack, they are wrapped in a Task.You can observe this behavior in the following example:
Here are the two methods from your original example, decompiled:
The latter generates a (useless) state machine and the exception actually gets caught and stored in
Task.Exception
. Because of that, the unhandled exception event is never triggered at all.Note, the compiler also warns when you write code like this, which kind of implies that it’s probably a mistake.
This is fully resolved between #2103 and #2319. Async main, and top-level async main, should work fine now (after those are both released).