闯入 C# 调试器以除零
我将 C# 与 XNA 库一起使用,但我的 Vector3 对象中突然出现 NaN。 当发生违规计算时(例如除以零),有没有办法闯入调试器? 目前该程序只是继续运行。 我用的是VS2008专业版。 例外对话框中的所有例外均在“用户未处理”列中选择。
编辑:澄清一下,我无法弄清楚错误的计算在哪里。 这就是为什么我希望调试器自动中断。 设置断点并不是一个解决方案。
I'm using C# with the XNA library and I'm getting NaNs cropping up in my Vector3 objects. Is there a way to break into the debugger when the offending calculation happens (e.g. a divide by zero)? Currently the program just continues running. I'm using VS2008 Professional. All the exceptions in the Exceptions dialog are selected in the "user-unhandled" column.
Edit: To clarify, I can't work out where the bad calculation is. This is why I want the debugger to break automatically. Setting breakpoints is not a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,将双精度数/浮点数除以零,得到无穷大/负无穷大,具体取决于双精度数是正数还是负数。 只有零双精度/浮点除以零才会给出 NaN。 无论哪种情况,都不会抛出异常。
您应该能够使用条件断点来检测特定变量何时设置为这些值之一。 但检查 NaN 时要小心,因为 NaN != NaN。
Firstly dividing a double/float by zero gives Infinity/-Infinity depending upon whether the double is positive or negative. Only a zero double/float divided by zero gives NaN. In either case, no exception will be thrown.
You should be able to use conditional breakpoints to detect when a particular variable gets set to one of these values. Be careful when checking for NaN though, as NaN != NaN.
听起来你正在以某种方式处理异常(就像捕获通用异常)你可以做的是按 Ctrl+alt+E 打开异常对话框 - 确保选中异常的“抛出时”复选框( s) 你感兴趣
Sounds like you're handling the exception somehow (like a catching a generic Exception) What you can do is press Ctrl+alt+E to bring up the exceptions dialog -- make sure you check the "when thrown" checkbox for the exception(s) you're interested in
您可以设置一个条件断点,该断点仅在表达式的除数为 0 时中断。
You could set a conditional breakpoint that only breaks when the divisor of an expression is 0.
我知道这是一篇旧文章,但是......
根据经验,我错误地使用它几乎总是 Vector3.Normalize 。
当我不确定它的长度是否为零时,我现在总是这样做
float L = V.Length();
如果(L!= 0.0)
V/=L;
归一化中除以零应该给出例外,但事实并非如此。 让我很头疼。
I know this is an old post but.....
from experience its nearly always Vector3.Normalize that i use by mistake.
When I'm not sure whether it will be zero length I now always do
float L = V.Length();
if(L != 0.0)
V /= L;
divide by zero in Normalize should give an exception but it doesn't. Caused me a lot of head scratching.