eyalroz / cuda-api-wrappers

Thin, unified, C++-flavored wrappers for the CUDA APIs
BSD 3-Clause "New" or "Revised" License
790 stars 80 forks source link

Should wrapper classes throw when failing on destruction? #440

Open eyalroz opened 1 year ago

eyalroz commented 1 year ago

Classes for streams, contexts, events etc. all make CUDA API calls on destruction - and those calls can, in theory, fail. Not just due to bugs in the wrappers, but due to driver issues, hardware issues, or even the developer using the wrapper artificially destroying things before the wrapper dtor kicks into action (and that's not even difficult to do: You can always get the wrapped handle).

Given that fact... what should I do with failure within the destructors? Should I still throw an exception, risking std::terminate in case the stack is being unwound? Or - should I fail silently, and "swallow" the error?

A third alternative would be checking std::uncaught_exception() and deciding based on that; but that means complex and somewhat convoluted destructor behavior.

eyalroz commented 1 year ago

@codecircuit : What do you think?