diff --git a/include/stdex/curl.hpp b/include/stdex/curl.hpp index 50600c192..5069c3c61 100644 --- a/include/stdex/curl.hpp +++ b/include/stdex/curl.hpp @@ -6,6 +6,7 @@ #pragma once #include "compat.hpp" +#include "exception.hpp" #include #include #include @@ -16,7 +17,7 @@ namespace stdex /// /// CURL runtime error /// - class curl_runtime_error : public std::runtime_error + class curl_runtime_error : public num_runtime_error { public: /// @@ -24,10 +25,9 @@ namespace stdex /// /// \param[in] num CURL error code /// - curl_runtime_error(_In_ CURLcode num) : - runtime_error(curl_easy_strerror(num)), - m_num(num) - {} + curl_runtime_error(_In_ error_type num) : stdex::num_runtime_error(num, curl_easy_strerror(num)) + { + } /// /// Constructs an exception @@ -35,10 +35,9 @@ namespace stdex /// \param[in] num CURL error code /// \param[in] msg Error message /// - curl_runtime_error(_In_ CURLcode num, _In_ const std::string& msg) : - runtime_error(msg + ": " + curl_easy_strerror(num)), - m_num(num) - {} + curl_runtime_error(_In_ error_type num, _In_ const std::string& msg) : stdex::num_runtime_error(num, msg + ": " + curl_easy_strerror(num)) + { + } /// /// Constructs an exception @@ -46,21 +45,12 @@ namespace stdex /// \param[in] num CURL error code /// \param[in] msg Error message /// - curl_runtime_error(_In_ CURLcode num, _In_z_ const char *msg) : - runtime_error(std::string(msg) + ": " + curl_easy_strerror(num)), - m_num(num) - {} - - /// - /// Returns the error number - /// - CURLcode number() const + curl_runtime_error(_In_ error_type num, _In_z_ const char *msg) : stdex::num_runtime_error(num, std::string(msg) + ": " + curl_easy_strerror(num)) { - return m_num; } protected: - CURLcode m_num; ///< Numeric error code + error_type m_num; ///< Numeric error code }; /// diff --git a/include/stdex/exception.hpp b/include/stdex/exception.hpp index 88b1ef4f4..a688d2134 100644 --- a/include/stdex/exception.hpp +++ b/include/stdex/exception.hpp @@ -41,4 +41,48 @@ namespace stdex catch (...) {} return ex.what(); } + + /// + /// Numerical runtime error + /// + template + class num_runtime_error : public std::runtime_error + { + public: + typedef _Tn error_type; ///< Error number type + + public: + /// + /// Constructs an exception + /// + /// \param[in] num Numeric error code + /// \param[in] msg Error message + /// + num_runtime_error(_In_ error_type num, _In_ const std::string& msg) : + m_num(num), + runtime_error(msg) + {} + + /// + /// Constructs an exception + /// + /// \param[in] num Numeric error code + /// \param[in] msg Error message + /// + num_runtime_error(_In_ error_type num, _In_z_ const char *msg) : + m_num(num), + runtime_error(msg) + {} + + /// + /// Returns the error number + /// + error_type number() const + { + return m_num; + } + + protected: + error_type m_num; ///< Numeric error code + }; }