csharpstandard
csharpstandard copied to clipboard
Documentation for exception thrown within `when` expression
Type of issue
Missing information
Description
I could not find good documentation on the expected behavior if an exception is thrown within the when expression. I wanted to confirm whether any additional exception handling was necessary in this use case.
Based on a quick test, it appears that the exception is suppressed, and the associated exception handler does not execute. Can the behavior be documented?
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/when
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/keywords/when.md
Document Version Independent Id
15502bbc-5355-2add-0fa8-ae31dc01c122
Article author
@BillWagner
Metadata
- ID: 6ef10b29-fbf8-5af9-8f8b-a694a1416e33
- Service: dotnet-csharp
- Sub-service: lang-reference
@janvorli who would be the best person to improve the docs for exception handling?
Adding @jcouv and @333fred
/cc @jskeet
I looked through the latest standard:
Neither specify behavior when evaluating an exception_filter throws an exception.
One requirement can be teased out: The language in the standard says that the catch clauses matches "when the exception_filter evalutes to true". Throwing an exception should mean the catch clause isn't execute.
The standard does have rules for the behavior when an exception is propagated from a catch clause, so the behavior when an exception filter thows an exception should be part of the standard.
If you both agree, I'll move this to the csharpstandard repo.
Yes, we should definitely document this.
@jskeet I propose adding this to the C# 8 milestone.
Yup, works for me.