Add operator for easier try-catch #8451
Unanswered
AkbarDizaji
asked this question in
Language Ideas
Replies: 2 comments
-
The whole point of exception handling is to not catch exceptions when you are not handling it. |
Beta Was this translation helpful? Give feedback.
0 replies
-
If you are doing enough try/catch blocks that it becomes a problem, your architecture might be wrong. Try/catch, as @huoyaoyuan implied, are for exceptional situations. If a method needs to open a file, write to it, then exit, it shouldn't do anything if the open fails because |
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
-
Proposal: Introduce the
?=
Operator for Simplified Exception HandlingSummary
Introduce a new operator
?=
that allows assigning the result of a function to a tuple containing a response and an error. This operator simplifies error handling by capturing the function’s result or any exception thrown, assigning the response or error accordingly.Motivation
Error handling in C# often requires verbose try-catch blocks, leading to repetitive and cluttered code. The
?=
operator aims to streamline this process by providing a concise way to handle operations that may fail, capturing the result or the exception in a structured manner.Detailed Design
Syntax
Beta Was this translation helpful? Give feedback.
All reactions