Skip to content

Commit

Permalink
Fixes #511: Can now construct errors with fully-overriden what() me…
Browse files Browse the repository at this point in the history
…ssage
  • Loading branch information
eyalroz authored and Eyal Rozenberg committed May 11, 2023
1 parent 4f0e8f0 commit c8db6db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/cuda/api/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ class runtime_error : public ::std::runtime_error {
runtime_error(status::named_t error_code, ::std::string&& what_arg) :
runtime_error(static_cast<status_t>(error_code), what_arg) { }

protected:
runtime_error(status_t error_code, ::std::runtime_error&& err) :
::std::runtime_error(::std::move(err)), code_(error_code)
{ }

public:
static runtime_error with_message_override(status_t error_code, ::std::string complete_what_arg)
{
return runtime_error(error_code, ::std::runtime_error(::std::move(complete_what_arg)));
}

/**
* Obtain the CUDA status code which resulted in this error being thrown.
*/
Expand Down
16 changes: 14 additions & 2 deletions src/cuda/rtc/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class runtime_error : public ::std::runtime_error {
code_(error_code)
{ }
// I wonder if I should do this the other way around
runtime_error(status_t<Kind> error_code, const ::std::string& what_arg) :
::std::runtime_error(what_arg + ": " + describe(error_code)),
runtime_error(status_t<Kind> error_code, ::std::string what_arg) :
::std::runtime_error(::std::move(what_arg) + ": " + describe(error_code)),
code_(error_code)
{ }
///@endcond
Expand All @@ -138,6 +138,17 @@ class runtime_error : public ::std::runtime_error {
runtime_error(status::named_t<Kind> error_code, const ::std::string& what_arg) :
runtime_error(static_cast<status_t<Kind>>(error_code), what_arg) { }

protected:
runtime_error(status_t<Kind> error_code, ::std::runtime_error err) :
::std::runtime_error(::std::move(err)), code_(error_code)
{ }

public:
static runtime_error with_message_override(status_t<Kind> error_code, ::std::string complete_what_arg)
{
return runtime_error<Kind>(error_code, ::std::runtime_error(complete_what_arg));
}

/**
* Obtain the CUDA status code which resulted in this error being thrown.
*/
Expand All @@ -147,6 +158,7 @@ class runtime_error : public ::std::runtime_error {
status_t<Kind> code_;
};


} // namespace rtc

// TODO: The following could use ::std::optional arguments - which would
Expand Down

0 comments on commit c8db6db

Please sign in to comment.