C# Compiler should give warning but doesn't?

后端 未结 7 1103
北恋
北恋 2020-12-03 14:05

Someone on my team tried fixing a \'variable not used\' warning in an empty catch clause.

try { ... } catch (Exception ex) { }

-> gives a w

相关标签:
7条回答
  • 2020-12-03 14:58

    Static analysis is somewhat limited in what it can accomplish today. (Although as Eric pointed out not because it doesn't know in this case.)

    The new Code Contracts in .NET 4 enhances static checking considerably and one day I'm sure you'll get more help with obvious bugs like this.

    If you've tried Code Contracts you'll know however that doing an exhaustive static analysis of your code is not easy - it can thrash for minutes after each compile. Will static analysis ever be able to find every problem like this at compile time? Probably not: see http://en.wikipedia.org/wiki/Halting_problem.

    0 讨论(0)
提交回复
热议问题