Skip to content
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

Proposal: Throw exception in null-coalescing operator #8399

Closed
lachbaer opened this issue Feb 4, 2016 · 2 comments
Closed

Proposal: Throw exception in null-coalescing operator #8399

lachbaer opened this issue Feb 4, 2016 · 2 comments

Comments

@lachbaer
Copy link
Contributor

lachbaer commented Feb 4, 2016

I think that there are often times where one would like to throw an exception if a value is null, like in

public string {
    get { return _myString; }
    set {
        if (value!=null) _myString = value;
        throw new ArgumentNullException();
    }
}

When allowing to throw an exception in the ?? Operator then things could be less verbose, but also quite understandable to everyone.

public string {
    get { return _myString; }
    set { _myString = value ?? throw new ArgumentNullException(); }
}
@alrz
Copy link
Member

alrz commented Feb 4, 2016

Dupe of #5143 (see 3rd point under "allowed in only the following contexts").

@lachbaer
Copy link
Contributor Author

lachbaer commented Feb 5, 2016

Ah, I see that it is already completely written down in https://github.com/dotnet/roslyn/blob/future/docs/features/patterns.md.
(Did my research, but didn't see the forrest because of all the trees ;-)

@lachbaer lachbaer closed this as completed Feb 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants