Exception contracts #3844
Replies: 2 comments
-
It was a decision very early in the C# language to depart from languages like Java that include exceptions in method contracts. It is something we're unlikely to revisit. However, I'm moving this issue to the language design repository in case there is further discussion. |
Beta Was this translation helpful? Give feedback.
-
This proposal seems less about checked exceptions and more about having a declarative way via attributes to declare exception handling, and having a "binary rewriter" that can implement that exception handling in your code. Theoretically a use case for AOP-style source generators, although I feel that this approach is significantly kludgier than just writing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This issue has been moved from a ticket on Developer Community.
In a similar way to code contracts allow an attribute based way to handle exceptions in a method. Often time exception handlers are responsible for similar tasks such logging and re-throwing.
it will be easier to add an attribute such:
[ExceptionHandlerAttribute(Type="ArgumentException", Handler=”HandlerFunctionName”)]
[ExceptionHandlerAttribute(Type= "FileNotFound", RetryCount=3, RetryDelay=”00:01”, Handler=”HandlerFunctionName”)]
Let a binary rewriter add the try/catch with the proper code end exception type in each catch block.
Original Comments
George Quiroga on 3/5/2020, 04:24 PM:
Something like this would be great. I spend a lot of time repeating similar try-catch and log exception handlers to much of my code. Having a shorter method of specifying handlers for exception processing would let me be more productive.
Visual Studio Feedback System on 3/5/2020, 11:45 PM:
Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.
Beta Was this translation helpful? Give feedback.
All reactions