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

Refactoring request: Remove redundant catch statement #1025

Closed
symbiogenesis opened this issue Jan 8, 2023 · 0 comments · Fixed by #1364
Closed

Refactoring request: Remove redundant catch statement #1025

symbiogenesis opened this issue Jan 8, 2023 · 0 comments · Fixed by #1364

Comments

@symbiogenesis
Copy link

symbiogenesis commented Jan 8, 2023

In the event that a catch block simply throws, and it is the last catch block, or the only catch block, then it can be removed.

try
{
   DoSomething();
}
catch
{
   throw;
}
finally
{
   DoSomethingElse();
}

should become:

try
{
   DoSomething();
}
finally
{
   DoSomethingElse();
}

If there are multiple catch blocks, and then last one is redundant, then only remove the last one.

try
{
   DoSomething();
}
catch (SomeException ex)
{
   HandleException(ex);
}
catch
{
   throw;
}

should become:

try
{
   DoSomething();
}
catch (SomeException ex)
{
   HandleException(ex);
}

And for a try-catch block with only one empty catch block, and no finally block, then the entire thing should be removed

try
{
   DoSomething();
}
catch
{
   throw;
}

should become

DoSomething();
@symbiogenesis symbiogenesis changed the title Refactoring request: Remove empty catch statement Refactoring request: Remove redundant catch statement Jan 8, 2023
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