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
|
#pragma once
|
||||||
|
|
||||||
#include "compat.hpp"
|
#include "compat.hpp"
|
||||||
|
#include "exception.hpp"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -16,7 +17,7 @@ namespace stdex
|
|||||||
///
|
///
|
||||||
/// CURL runtime error
|
/// CURL runtime error
|
||||||
///
|
///
|
||||||
class curl_runtime_error : public std::runtime_error
|
class curl_runtime_error : public num_runtime_error<CURLcode>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
@ -24,43 +25,32 @@ namespace stdex
|
|||||||
///
|
///
|
||||||
/// \param[in] num CURL error code
|
/// \param[in] num CURL error code
|
||||||
///
|
///
|
||||||
curl_runtime_error(_In_ CURLcode num) :
|
curl_runtime_error(_In_ error_type num) : stdex::num_runtime_error<CURLcode>(num, curl_easy_strerror(num))
|
||||||
runtime_error(curl_easy_strerror(num)),
|
{
|
||||||
m_num(num)
|
}
|
||||||
{}
|
|
||||||
|
///
|
||||||
///
|
/// Constructs an exception
|
||||||
/// Constructs an exception
|
///
|
||||||
///
|
/// \param[in] num CURL error code
|
||||||
/// \param[in] num CURL error code
|
/// \param[in] msg Error message
|
||||||
/// \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))
|
||||||
curl_runtime_error(_In_ CURLcode num, _In_ const std::string& msg) :
|
{
|
||||||
runtime_error(msg + ": " + curl_easy_strerror(num)),
|
}
|
||||||
m_num(num)
|
|
||||||
{}
|
///
|
||||||
|
/// Constructs an exception
|
||||||
///
|
///
|
||||||
/// Constructs an exception
|
/// \param[in] num CURL error code
|
||||||
///
|
/// \param[in] msg Error message
|
||||||
/// \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))
|
||||||
///
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
return m_num;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CURLcode m_num; ///< Numeric error code
|
error_type m_num; ///< Numeric error code
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -41,4 +41,48 @@ namespace stdex
|
|||||||
catch (...) {}
|
catch (...) {}
|
||||||
return ex.what();
|
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