简体   繁体   中英

How can i find all empty catch with resharper?

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

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$)
{
}

整形器找到模式

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM