Catching Math Errors

I am working on a console algorithm that does math stuff and then writes the results to a text file. The problem is, at times the math may include a sqrt(-1) or (1/0) situation. Instead of getting some kind of error exception, it just writes QNAN or -1.#IND to the file and keeps chugging along (even though the original arrays were Dim’d as Double). The program reading this is confused.

I have tried

if not IsNumber then

but that didn’t seem to catch the -1.#IND.

So in short, is there an easy way to test for math errors within Xojo?

Thanks!

The test I used was if not IsNumeric(MyArray(i)) then

Here is the long version so you can paste it into a button event to see what is going on, what I do in my code is use extension methods. There is some information in the language reference under ‘Double’ and it leads you to believe there should be a NaN but it is represented as IND for some reason - a bug or documentation error maybe?

  dim result1, result2 as double
  dim testINF, testNAN, testIND as boolean
  
  // should get INF or -INF
  result1 = 1.0 / 0.0
  
  if Str(result1).Uppercase.InStr("INF") <> 0 then
    testINF = true
  end
  
  if Str(result1).Uppercase.InStr("NAN") <> 0 then
    testNAN = true
  end
  
  if Str(result2).Uppercase.InStr("IND") <> 0 then
    testIND = true
  end
  
  // should get NaN but we get IND (indeterminate)
  result2 = Sqrt(-1.0)
  
  if Str(result2).Uppercase.InStr("INF") <> 0 then
    testINF = true
  end
  
  if Str(result2).Uppercase.InStr("NAN") <> 0 then
    testNAN = true
  end
  
  if Str(result2).Uppercase.InStr("IND") <> 0 then
    testIND = true
  end