xxx SAFE_CALL() is a good solution? - Serbipunk/notes GitHub Wiki

#define NVRTC_SAFE_CALL(Name, x)                                \
  do {                                                          \
    nvrtcResult result = x;                                     \
    if (result != NVRTC_SUCCESS) {                              \
      std::cerr << "\nerror: " << Name << " failed with error " \
                << nvrtcGetErrorString(result);                 \
      exit(1);                                                  \
    }                                                           \
  } while (0)
// Macro to catch CUDA errors in CUDA runtime calls
#define CUDA_SAFE_CALL(call)                                               
do {                                                                  
    cudaError_t err = call;                                           
    if (cudaSuccess != err) {                                         
        fprintf (stderr, "Cuda error in file '%s' in line %i : %s.", 
                 __FILE__, __LINE__, cudaGetErrorString(err) );       
        exit(EXIT_FAILURE);                                          
    }                                                                
} while (0)
// Error-checking wrapper around GL calls
#define GL_SAFE_CALL(call)              \
{                                   \
    GLenum err;                     \
    call;                           \
    err = glGetError();             \
    if(err != GL_NO_ERROR)          \
    {                               \
        fprintf(stderr, "%s:%d GL error: %d\n", __FILE__, __LINE__, err);    \
        cleanup(FAILURE);           \
    }                               \
}