Without looking at the code, this answer will be unclear, but one way to do this is to check the output from your function, and if it is "NaN" raise and exclude:
if (double.IsNaN(result))
{
throw new ArithmeticException();
}
But with more details on the exception.
UPDATE
To trap where a particular exception is thrown, you can (temporarily) break when the exception is thrown in the debugger.
Select Debug> Exceptions , then expand the tree to select Common Language Exceptions> System> System.ArithmeticException and select the Thrown check box.
, , , . .