Exception Handling#
2026-10-23
1 min read time
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_EXCEPTIONSbefore including any library headers.By compiling with
-fno-exceptionscompiler flag withgccorclang, or/EH-compiler flag withmsvc.
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;
};