调试器步入如果()块,其中条件为假 [英] Debugger stepping into if() block where condition is false
问题描述
由于这种宝石code的:
Given this gem of code:
class Program
{
private static bool IsAdmin = true;
static void Main(string[] args)
{
if (!IsAdmin)
{
throw new Exception();
}
try
{
var x = 2342342;
var y = 123132;
}
catch (Exception)
{
throw;
}
}
}
由于 this.IsAdmin
产生真实的 - 我希望调试器不进if语句。在现实中它 - 它在步扔,但实际上并没有丢
Given the this.IsAdmin
yields true - I would expect the debugger to not enter that if statement. In reality it does - and it steps over the throw but does not actually throw!
现在,当你有一个if语句后面一个try / catch块中的异常这只是发生,在Visual Studio的2013年,针对.NET Framework 4中,64位,preFER 32位选中。
Now this only happens when you have an exception inside an if statement followed by a try/catch block, on Visual Studio 2013, targeting .NET Framework 4, 64 bit, "Prefer 32 bit" unchecked.
我已经证实了这一点古怪与不同的机器上的同事。虽然步以下code和调试器会显得步入如果分支,但没有抛出异常:
I have confirmed this oddity with colleagues on different machines. Step though the following code and the debugger will seem to step into the if branch, but no exception is thrown:
我在调试模式下,我曾尝试编译和清洁项目多次。
I am in debug mode, I have tried compiling and cleaning the project multiple times.
任何人能解释为什么会这样?
Can anyone explain why this is happening?
推荐答案
请参阅下面的链接。它是在Visual Studio和.NET框架versiosn的某些版本中的已知错误:
See the link below. It is a known bug in some versions of visual studio and .NET framework versiosn:
<一个href=\"http://whileicompile.word$p$pss.com/2010/07/02/visual-studio-bug-if-followed-by-a-try-catch-causes-debugger-stepping-error/\">http://whileicompile.word$p$pss.com/2010/07/02/visual-studio-bug-if-followed-by-a-try-catch-causes-debugger-stepping-error/
这是完全无害的,是你将不得不住在一起。
It it completely harmless and something you will just have to live with.
这篇关于调试器步入如果()块,其中条件为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!