Improve handling of CUDA API errors