The suggested solution with NaNMath package is ok and works, but:

Is there any way to make all math functions return NaN in a large block of code? Like I have a block like this:

```
for i in ...:
a[i] = sqrt(f(i))
...
if ...:
arr = [sqrt(f(j)) for j in ...]
b[i] = log(f(arr))
...
end
```

And would really like all functions like `sqrt`

and `log`

here to just produce nans. The only way I see is manually find offending function and replace them with `NaNMath`

implementations. Oh, and what to do if `f(...)`

- some external function - also contains `sqrt`

and others, and thus throws domainerror instead of just returning nan? And if I forget some function, which just happens not to throw when run on test data, it will explode at some unexpected time later.

Note that in this example itâ€™s not easily possible to put `catch`

es in relevant locations. Even for simpler examples, this looks far from an expected quick solutionâ€¦