C#: Find all empty catch blocks

前端 未结 9 1288
逝去的感伤
逝去的感伤 2020-12-23 22:08

I am reviewing some code.

I have notice some empty catch blocks. Not a good idea since somethings do not work and you cannot see why.

Is there an easy way to

9条回答
  •  囚心锁ツ
    2020-12-23 22:52

    Expanding on @bobah75 's answer, it wouldn't recognize this line

    catch (System.Data.Entity.Core.EntityException ex)
    {
    }
    

    So to fix that, here is the solution

    catch\s*(\(?.+Exception(\s*\w+)?\))?\s*\{\s*([:b\n]|(\/\*[^*]*\*\/)|(//[^\n]*))*\}
    

    you can test it out here

提交回复
热议问题