[Proposal]: async method exception filter #9000
Unanswered
jcouv
asked this question in
Language Ideas
Replies: 2 comments
-
This is something I'd love to have, but I'm curious will this retain the contextual variables? public Task M()
{
using (_logger.BeginScope("label"))
await SomeMethodThatThrows();
} If I wrap this with a logging filter the scope will be lost normally in the async transformation. public Task M()
{
using (_logger.BeginScope("label"))
{
try{ await SomeMethodThatThrows();}
catch(Exception e) when (LoggingFilter(_logger, e)){}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Would it be useful to also be able to apply this attribute to specific methods to opt-in to the exception filter where needed instead of it affecting the entire assembly? |
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
-
async method exception filter
Champion issue: #9001
Summary
Allow customizing the exception handling produced for async methods.
Adding the following attribute:
[module: AsyncExceptionFilter(typeof(MyExceptionHandler)]
would result in the generated
try/catch
having a modifiedcatch
clause:where we could find the following method
void Report(Exception)
.Motivation
There's exception handling that is better done inside the async method so that it can see the original stacktrace and can produce useful crash dumps, but it can be painful to repeat in every async method.
The roslyn IDE code is an example, where there is desire to add the following pattern to every async method:
Example
FatalError
Design Meetings
Beta Was this translation helpful? Give feedback.
All reactions