Exception Handling

Contents

Exception Handling#

2026-10-23

1 min read time

Applies to Linux and Windows

Standard C++ exception handling (try, catch, throw) is not supported in HIP device code, while it is enabled by default in host code.

Device code

libhipcxx maps exceptions to cuda::std::terminate() calls in device code, which traps and terminates the kernel.

Host code

libhipcxx allows users to manually disable exceptions in host code in two ways:

  • By defining CCCL_DISABLE_EXCEPTIONS before including any library headers.

  • By compiling with -fno-exceptions compiler flag with gcc or clang, or /EH- compiler flag with msvc.

If exceptions are disabled, a throw exception is translated into a cuda::std::terminate() call, which terminates the program.

cuda::cuda_error#

Exception class thrown when a HIP runtime error is encountered. It inherits from std::runtime_error.

class cuda_error : public std::runtime_error
{
public:
    cuda_error(hipError_t status, const char* msg);

    hipError_t status() const noexcept;
};