Detecting Compute shader divide by zero

So I had this annoying bug where a hole sometimes appeared in a procedurally created mesh. I was creating the mesh using a compute shader. Eventually I realised that I had an edge case in my algorithm where it was possible for a vector I was normalising to be zero. The fix was easy but finding the issue was very difficult. In C# (or C++) it’s fairly easy to find these sort of run time errors using exceptions but does anyone know if there is a reliable way to do this with code running on the GPU?

The really weird thing was that I sanity checked the verts returned from the compute shader and couldn’t see a problem with them. But when I passed them to the mesh renderer that’s when the issue showed up.

It’s fixed now.

To avoid dividing by zero I generally multiply…when I can… Such as instead of dividing by 2 I multiply by 0.5 or the inverse if not a constant;