Skip to content

Commit c246ed1

Browse files
committed
Merge pull request #83 from hatkirby/master
Added back error codes to exceptions
2 parents afab344 + 0aaa6ca commit c246ed1

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

include/curl_exception.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,21 @@ namespace curl {
9898
* This constructor allows to specify a custom error message and the method name where
9999
* the exception has been thrown.
100100
*/
101-
curl_easy_exception(const std::string &error, const std::string &method) : curl_exception(error,method) {}
101+
curl_easy_exception(const std::string &error, const std::string &method) : curl_exception(error,method), code(CURLE_OK) {}
102102
/**
103103
* The constructor will transform a CURLcode error in a proper error message.
104104
*/
105-
curl_easy_exception(const CURLcode &code, const std::string &method) : curl_exception(curl_easy_strerror(code),method) {}
105+
curl_easy_exception(const CURLcode &code, const std::string &method) : curl_exception(curl_easy_strerror(code),method), code(code) {}
106+
107+
/**
108+
* Returns the error code if there is one. Returns CURLE_OK if none has been set.
109+
*/
110+
inline CURLcode get_code() const {
111+
return code;
112+
}
113+
114+
private:
115+
CURLcode code;
106116
};
107117

108118
/**
@@ -115,11 +125,21 @@ namespace curl {
115125
* This constructor enables setting a custom error message and the method name where
116126
* the exception has been thrown.
117127
*/
118-
curl_multi_exception(const std::string &error, const std::string &method) : curl_exception(error,method) {}
128+
curl_multi_exception(const std::string &error, const std::string &method) : curl_exception(error,method), code(CURLM_OK) {}
119129
/**
120130
* The constructor will transform a CURLMcode error to a proper error message.
121131
*/
122-
curl_multi_exception(const CURLMcode code, const std::string &method) : curl_exception(curl_multi_strerror(code),method) {}
132+
curl_multi_exception(const CURLMcode code, const std::string &method) : curl_exception(curl_multi_strerror(code),method), code(code) {}
133+
134+
/**
135+
* Returns the error code if there is one. Returns CURLM_OK if none has been set.
136+
*/
137+
inline CURLMcode get_code() const {
138+
return code;
139+
}
140+
141+
private:
142+
CURLMcode code;
123143
};
124144

125145
/**
@@ -132,11 +152,21 @@ namespace curl {
132152
* This constructor enables setting a custom error message and the method name where
133153
* the exception has been thrown.
134154
*/
135-
curl_share_exception(const std::string &error, const std::string &method) : curl_exception(error,method) {}
155+
curl_share_exception(const std::string &error, const std::string &method) : curl_exception(error,method), code(CURLSHE_OK) {}
136156
/**
137157
* The constructor will transform a CURLSHcode error in a proper error message.
138158
*/
139-
curl_share_exception(const CURLSHcode code, const std::string &method) : curl_exception(curl_share_strerror(code),method) {}
159+
curl_share_exception(const CURLSHcode code, const std::string &method) : curl_exception(curl_share_strerror(code),method), code(code) {}
160+
161+
/**
162+
* Returns the error code if there is one. Returns CURLE_OK if none has been set.
163+
*/
164+
inline CURLSHcode get_code() const {
165+
return code;
166+
}
167+
168+
private:
169+
CURLSHcode code;
140170
};
141171
}
142172

0 commit comments

Comments
 (0)