csharpstandard icon indicating copy to clipboard operation
csharpstandard copied to clipboard

Documentation for exception thrown within `when` expression

Open romglusker opened this issue 1 year ago • 5 comments
trafficstars

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

romglusker avatar Apr 18 '24 17:04 romglusker

@janvorli who would be the best person to improve the docs for exception handling?

adamsitnik avatar Apr 19 '24 14:04 adamsitnik

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.

BillWagner avatar Apr 19 '24 14:04 BillWagner

Yes, we should definitely document this.

jskeet avatar Apr 19 '24 15:04 jskeet

@jskeet I propose adding this to the C# 8 milestone.

BillWagner avatar Apr 25 '24 13:04 BillWagner

Yup, works for me.

jskeet avatar Apr 25 '24 13:04 jskeet