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

SA1513 doesn't allow throw exception from simplified switch #3410

Closed
DenisDoroshko opened this issue Nov 30, 2021 · 0 comments · Fixed by #3418
Closed

SA1513 doesn't allow throw exception from simplified switch #3410

DenisDoroshko opened this issue Nov 30, 2021 · 0 comments · Fixed by #3418

Comments

@DenisDoroshko
Copy link

DenisDoroshko commented Nov 30, 2021

Get error in case like this:

throw response.StatusCode switch
{
        HttpStatusCode.NotFound => new NotFoundException("Not found error"),
         _ => new ApiException("Api exception")
};

And to fix this error I need to do something like this:

throw response.StatusCode switch
{
        HttpStatusCode.NotFound => new NotFoundException("Not found error"),
         _ => new ApiException("Api exception")
}

;

I also can introduce variable for exception and then throw it, and It's also not a good decision
Can it be fixed or I'm doing something wrong?

@DenisDoroshko DenisDoroshko changed the title SA1513 get error when use throw with switch SA1513 doesn't allow throw exception from simplified switch Nov 30, 2021
sharwell added a commit to sharwell/StyleCopAnalyzers that referenced this issue Dec 8, 2021
@sharwell sharwell self-assigned this Dec 8, 2021
@sharwell sharwell added this to the 1.2-beta.next milestone Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants