-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code annotation for Exceptions #79647
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Making |
Thanks for the swift response @KalleOlaviNiemitalo |
NotNullAttribute on an input parameter already means that, if the function returns, then the compiler can assume that the argument was not null. |
True but not in the context of an exception (or whether we can continue the control flow after the method in question). |
Problem
In the current setup, there is no way of telling that a method will throw an exception so that the code after will not be executed. A small example:
Even though
AlwaysThrow
will never return and will throw an exception the method would not be compilable without the additional (and useless)throw
at the end (or areturn
statement).Real-world example
I encountered this problem most often in combination with
ExceptionDispatchInfo
:New behavior
We already have
DoesNotReturn
andDoesNotReturnIf
which could be a good beginning. If a method is flagged by this annotation the compiler should understand that the code afterward will never be reached. In its current stateDoesNotReturnIf
only understands a boolean input, maybe a newDoesNotReturnIfNull
would also be helpful.PS: I did neither add this as a proposal nor as a bug as I wasn't sure what category fits best.
The text was updated successfully, but these errors were encountered: