exception, curl: switch to a reusable numbered errors
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
e0cbc4a90a
commit
7aa64cb625
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "compat.hpp"
|
||||
#include "exception.hpp"
|
||||
#include <curl/curl.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -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<CURLcode>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@ -24,43 +25,32 @@ namespace stdex
|
||||
///
|
||||
/// \param[in] num CURL error code
|
||||
///
|
||||
curl_runtime_error(_In_ CURLcode num) :
|
||||
runtime_error(curl_easy_strerror(num)),
|
||||
m_num(num)
|
||||
{}
|
||||
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \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)
|
||||
{}
|
||||
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \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) : stdex::num_runtime_error<CURLcode>(num, curl_easy_strerror(num))
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \param[in] num CURL error code
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
curl_runtime_error(_In_ error_type num, _In_ const std::string& msg) : stdex::num_runtime_error<CURLcode>(num, msg + ": " + curl_easy_strerror(num))
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \param[in] num CURL error code
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
curl_runtime_error(_In_ error_type num, _In_z_ const char *msg) : stdex::num_runtime_error<CURLcode>(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
|
||||
};
|
||||
|
||||
///
|
||||
|
@ -41,4 +41,48 @@ namespace stdex
|
||||
catch (...) {}
|
||||
return ex.what();
|
||||
}
|
||||
|
||||
///
|
||||
/// Numerical runtime error
|
||||
///
|
||||
template <typename _Tn>
|
||||
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
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user