Skip to content

Commit

Permalink
Make sure errors are included in the doxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Oct 25, 2023
1 parent e6b237e commit ca428fe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
5 changes: 4 additions & 1 deletion doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,11 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

# Need to specify the error.hpp file explicitly because it is excluded by the
# EXCLUDE_PATTERNS below.
INPUT = main_page.md \
../include
../include \
../include/rmm/detail/error.hpp

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
56 changes: 42 additions & 14 deletions include/rmm/detail/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@

namespace rmm {

/**
* @addtogroup errors
* @{
* @file
*/

/**
* @brief Exception thrown when logical precondition is violated.
*
* @ingroup errors
*
* This exception should not be thrown directly and is instead thrown by the
* RMM_EXPECTS macro.
*
Expand All @@ -45,6 +41,8 @@ struct logic_error : public std::logic_error {
/**
* @brief Exception thrown when a CUDA error is encountered.
*
* @ingroup errors
*
*/
struct cuda_error : public std::runtime_error {
using std::runtime_error::runtime_error;
Expand All @@ -53,12 +51,28 @@ struct cuda_error : public std::runtime_error {
/**
* @brief Exception thrown when an RMM allocation fails
*
* @ingroup errors
*
*/
class bad_alloc : public std::bad_alloc {
public:
/**
* @brief Constructs a bad_alloc with the error message.
*
* @param msg Message to be associated with the exception
*/
bad_alloc(const char* msg) : _what{std::string{std::bad_alloc::what()} + ": " + msg} {}

/**
* @brief Constructs a bad_alloc with the error message.
*
* @param msg Message to be associated with the exception
*/
bad_alloc(std::string const& msg) : bad_alloc{msg.c_str()} {}

/**
* @briefreturn{The explanatory string}
*/
[[nodiscard]] const char* what() const noexcept override { return _what.c_str(); }

private:
Expand All @@ -68,24 +82,37 @@ class bad_alloc : public std::bad_alloc {
/**
* @brief Exception thrown when RMM runs out of memory
*
* @ingroup errors
*
* This error should only be thrown when we know for sure a resource is out of memory.
*/
class out_of_memory : public bad_alloc {
public:
/**
* @brief Constructs an out_of_memory with the error message.
*
* @param msg Message to be associated with the exception
*/
out_of_memory(const char* msg) : bad_alloc{std::string{"out_of_memory: "} + msg} {}

/**
* @brief Constructs an out_of_memory with the error message.
*
* @param msg Message to be associated with the exception
*/
out_of_memory(std::string const& msg) : out_of_memory{msg.c_str()} {}
};

/**
* @brief Exception thrown when attempting to access outside of a defined range
*
* @ingroup errors
*
*/
class out_of_range : public std::out_of_range {
using std::out_of_range::out_of_range;
};

/** @} */ // end of group

} // namespace rmm

#define STRINGIFY_DETAIL(x) #x
Expand All @@ -106,12 +133,13 @@ class out_of_range : public std::out_of_range {
* // throws std::runtime_error
* RMM_EXPECTS(p != nullptr, "Unexpected nullptr", std::runtime_error);
* ```
* @param[in] _condition Expression that evaluates to true or false
* @param[in] _what String literal description of why the exception was
* thrown, i.e. why `_condition` was expected to be true.
* @param[in] _expection_type The exception type to throw; must inherit
* std::exception. If not specified (i.e. if only two macro
* arguments are provided), defaults to rmm::logic_error
* @param ... This macro accepts either two or three arguments:
* - The first argument must be an expression that evaluates to true or
* false, and is the condition being checked.
* - The second argument is a string literal used to construct the `what` of
* the exception.
* - When given, the third argument is the exception to be thrown. When not
* specified, defaults to `rmm::logic_error`.
* @throw `_exception_type` if the condition evaluates to 0 (false).
*/
#define RMM_EXPECTS(...) \
Expand Down

0 comments on commit ca428fe

Please sign in to comment.