NVIDIA / NVIDIA/cccl

[FEA]: Enable exceptions by default

Open
#2,303 8 comments 4 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

### Is this a duplicate?

- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this request and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)

### Area

libcu++

### Is your feature request related to a problem? Please describe.

_**Originally posted by @kroburg at https://github.com/NVIDIA/cuCollections/issues/589**_

`cuda::stream_ref::wait` can throw exceptions
```cpp
void wait() const
{
_CCCL_TRY_CUDA_API(::cudaStreamSynchronize, "Failed to synchronize stream.", get());
}
```

```cpp
_CCCL_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY void __throw_cuda_error(::cudaError_t, const char*)
{
_CUDA_VSTD_NOVERSION::terminate();
}
```

but `throw` terminates normally with a return value of 0.

```cpp
_CCCL_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY void terminate() noexcept
{
__cccl_terminate();
_LIBCUDACXX_UNREACHABLE();
}
```

```cpp
_CCCL_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY void __cccl_terminate() noexcept
{
NV_IF_ELSE_TARGET(NV_IS_HOST, (::std::exit(0);), (__trap();))
_LIBCUDACXX_UNREACHABLE();
}
```

CCCL disables exceptions by default, meaning that most APIs that are expected to throw exceptions never throw. One reason for this is that destructors should never throw exceptions (#683). Could we revisit this decision and consider enabling exceptions by default?

### Describe the solution you'd like

Enable exceptions and find a proper way to "throw".

### Describe alternatives you've considered

_No response_

### Additional context

Not sure about the scope of this request, this could be a general CCCL feature request.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.