Home > Software design >  How can i find all empty catch with resharper?
How can i find all empty catch with resharper?

Time:01-03

I know that there is the possibility to use search pattern but I don't know how to implement this feature

CodePudding user response:

You can mark any code in Visual Studio and then click, for example the empty try-catch, then go

  • Extensions -> Resharper -> Find -> Search with pattern

Now resharper created a pattern for you matching that code:

try
{
$statement$
}
catch ($Exception$ $e$)
{
}

reshaper find pattern

You can edit it or add new placeholders and save it, then click Find.

In this case it might be a good idea to add another pattern that matches also empty catch blocks that have no Exception parameter:

try
{
$statement$
}
catch
{
}

By the way, this matches also if the catch contains comments like

// don't do anything
  • Related