-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Parsing of C++ Exception String #10637
Changes from all commits
9f995bc
63bedda
9a49c9d
19acc1f
9581937
fa476a2
fe8961d
a2b4a09
7f6a03e
5ccf7e8
e1d417e
5be0e33
c918b37
0633d72
dde4e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,37 +99,65 @@ struct fatal_cuda_error : public cuda_error { | |
* @brief Macro for checking (pre-)conditions that throws an exception when | ||
* a condition is violated. | ||
* | ||
* Defaults to throwing `cudf::logic_error`, but a custom exception may also be | ||
* specified. | ||
* | ||
* Example usage: | ||
* | ||
* @code | ||
* CUDF_EXPECTS(lhs->dtype == rhs->dtype, "Column type mismatch"); | ||
* @endcode | ||
* // throws cudf::logic_error | ||
* CUDF_EXPECTS(lhs.type() != rhs.type(), "Column type mismatch"); | ||
* | ||
* @param[in] cond Expression that evaluates to true or false | ||
* @param[in] reason String literal description of the reason that cond is | ||
* expected to be true | ||
* @throw cudf::logic_error if the condition evaluates to false. | ||
* // throws std::invalid_argument | ||
* CUDF_EXPECTS(not cudf::is_nested(child_col.type()), std::invalid_argument, | ||
* "Nested types are not supported."); | ||
* @endcode | ||
*/ | ||
#define CUDF_EXPECTS(cond, reason) \ | ||
(!!(cond)) ? static_cast<void>(0) \ | ||
: throw cudf::logic_error("cuDF failure at: " __FILE__ \ | ||
":" CUDF_STRINGIFY(__LINE__) ": " reason) | ||
#define CUDF_EXPECTS(...) \ | ||
GET_CUDF_EXPECTS_MACRO(__VA_ARGS__, CUDF_EXPECTS_3, CUDF_EXPECTS_2) \ | ||
(__VA_ARGS__) | ||
|
||
//! @cond Doxygen_Suppress | ||
#define GET_CUDF_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME | ||
|
||
/** @param[in] _condition Expression that evaluates to true or false | ||
* @param[in] _expection_type The exception type to throw; must inherit | ||
* `std::exception`. If not specified (i.e. if only two macro | ||
Comment on lines
+124
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a |
||
* arguments are provided), defaults to `cudf::logic_error` | ||
* @param[in] _what String literal description of why the exception was | ||
* thrown, i.e. why `_condition` was expected to be true. | ||
* @throw `_exception_type` if the condition evaluates to 0 (false). | ||
*/ | ||
#define CUDF_EXPECTS_3(_condition, _exception_type, _reason) \ | ||
(!!(_condition)) ? static_cast<void>(0) : throw _exception_type \ | ||
{ \ | ||
"cuDF failure at: " __FILE__ ":" CUDF_STRINGIFY(__LINE__) ": " _reason \ | ||
} | ||
#define CUDF_EXPECTS_2(_condition, _reason) CUDF_EXPECTS_3(_condition, cudf::logic_error, _reason) | ||
//! @endcond | ||
|
||
/** | ||
* @brief Indicates that an erroneous code path has been taken. | ||
* | ||
* In host code, throws a `cudf::logic_error`. | ||
* | ||
* | ||
* Example usage: | ||
* ``` | ||
* ```c++ | ||
* // Throws `cudf::logic_error` | ||
* CUDF_FAIL("Non-arithmetic operation is not supported"); | ||
* ``` | ||
* | ||
* @param[in] reason String literal description of the reason | ||
* // Throws `std::invalid_argument` | ||
* CUDF_FAIL("Unsupported type for operation", std::invalid_argument); | ||
* ``` | ||
*/ | ||
#define CUDF_FAIL(reason) \ | ||
throw cudf::logic_error("cuDF failure at: " __FILE__ ":" CUDF_STRINGIFY(__LINE__) ": " reason) | ||
#define CUDF_FAIL(...) \ | ||
GET_CUDF_FAIL_MACRO(__VA_ARGS__, CUDF_FAIL_2, CUDF_FAIL_1) \ | ||
(__VA_ARGS__) | ||
//! @cond Doxygen_Suppress | ||
#define GET_CUDF_FAIL_MACRO(_1, _2, NAME, ...) NAME | ||
#define CUDF_FAIL_2(_what, _exception_type) \ | ||
/*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \ | ||
throw _exception_type{"cuDF failure at:" __FILE__ ":" CUDF_STRINGIFY(__LINE__) ": " _what}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe for DRY this should just call |
||
#define CUDF_FAIL_1(_what) CUDF_FAIL_2(_what, cudf::logic_error) | ||
//! @endcond | ||
|
||
namespace cudf { | ||
namespace detail { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,8 +141,14 @@ struct TypeList<Types<TYPES...>> { | |
* @param x The statement to be tested | ||
* @param msg The message associated with the exception | ||
*/ | ||
#define CUDF_EXPECT_THROW_MESSAGE(x, msg) \ | ||
EXPECT_THROW_MESSAGE(x, cudf::logic_error, "cuDF failure at:", msg) | ||
#define CUDF_EXPECT_THROW_MESSAGE(...) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know when these test macros snuck in, but I recall a long time ago advocating strongly against them. I think it's fragile and unimportant for us to be testing for the exact contents of an exceptions error message. Don't block this PR on removing these, but file it away in your memory banks for future work. |
||
GET_CUDF_EXPECT_THROW_MESSAGE_MACRO( \ | ||
__VA_ARGS__, CUDF_EXPECT_THROW_MESSAGE_3, CUDF_EXPECT_THROW_MESSAGE_2) \ | ||
(__VA_ARGS__) | ||
#define GET_CUDF_EXPECT_THROW_MESSAGE_MACRO(_1, _2, _3, NAME, ...) NAME | ||
#define CUDF_EXPECT_THROW_MESSAGE_3(x, exception, msg) \ | ||
EXPECT_THROW_MESSAGE(x, exception, "cuDF failure at:", msg) | ||
#define CUDF_EXPECT_THROW_MESSAGE_2(x, msg) CUDF_EXPECT_THROW_MESSAGE_3(x, cudf::logic_error, msg) | ||
|
||
/** | ||
* @brief test macro to be expected to throw cudf::cuda_error with a message | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==
? (or else this is expecting lhs and rhs to having mismatching types so the error string is backwards?)