C # debug break to divide by zero

I use C # with the XNA library, and I get NaNs in my Vector3 objects. Is there a way to get into the debugger when an abusive calculation occurs (e.g. division by zero)? Currently, the program continues to work. I am using VS2008 Professional. All exceptions in the Exceptions dialog box are selected in the Custom Unprocessed column.

Edit: To clarify, I can't figure out where the calculation is bad. This is why I want the debugger to crash automatically. Setting breakpoints is not a solution.

+3
source share
4 answers

-, double/float Infinity/-Infinity , double . double/float, , NaN. .

, , . NaN, , NaN!= NaN.

double a = double.NaN;
Console.Out.WriteLine(a == double.NaN); // false
Console.Out.WriteLine(a == a); // false
Console.Out.WriteLine(double.IsNaN(a)); // true
+4

, - (, ). , Ctrl + alt + E, - , "when throw" (),

+4

, , 0.

+3

, , .....

Vector3.Normalize, .

When I'm not sure if it will be zero length, I always do now

float L = V.Length (); if (L! = 0.0) V / = L;

division by zero in Normalize should throw an exception, but it is not. Caused a lot of scratches on my head.

+1
source

Source: https://habr.com/ru/post/1705682/


All Articles