00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00049 #ifndef INETSTL_INCL_INETSTL_ERROR_HPP_EXCEPTIONS
00050 #define INETSTL_INCL_INETSTL_ERROR_HPP_EXCEPTIONS
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define INETSTL_VER_INETSTL_ERROR_HPP_EXCEPTIONS_MAJOR 4
00054 # define INETSTL_VER_INETSTL_ERROR_HPP_EXCEPTIONS_MINOR 2
00055 # define INETSTL_VER_INETSTL_ERROR_HPP_EXCEPTIONS_REVISION 1
00056 # define INETSTL_VER_INETSTL_ERROR_HPP_EXCEPTIONS_EDIT 42
00057 #endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifndef INETSTL_INCL_INETSTL_H_INETSTL
00072 # include <inetstl/inetstl.h>
00073 #endif
00074 #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXCEPTIONS
00075 # include <stlsoft/error/exceptions.hpp>
00076 #endif
00077 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_EXCEPTION_STRING
00078 # include <stlsoft/util/exception_string.hpp>
00079 #endif
00080
00081 #ifndef INETSTL_OS_IS_WINDOWS
00082 # include <errno.h>
00083 #endif
00084
00085 #ifndef STLSOFT_CF_EXCEPTION_SUPPORT
00086 # error This file cannot be included when exception-handling is not supported
00087 #endif
00088
00089
00090
00091
00092
00093 #ifndef _INETSTL_NO_NAMESPACE
00094 # if defined(_STLSOFT_NO_NAMESPACE) || \
00095 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00096
00097 namespace inetstl
00098 {
00099 # else
00100
00101
00102 namespace stlsoft
00103 {
00104
00105 namespace inetstl_project
00106 {
00107
00108 # endif
00109 #endif
00110
00111
00112
00113
00114
00120 class internet_exception
00121 : public os_exception
00122 {
00125 protected:
00126 typedef stlsoft_ns_qual(exception_string) string_type;
00127 public:
00128 typedef os_exception parent_class_type;
00129 #ifdef INETSTL_OS_IS_WINDOWS
00130 typedef is_dword_t error_code_type;
00131 #else
00132 typedef int error_code_type;
00133 #endif
00134 typedef internet_exception class_type;
00136
00139 public:
00140 ss_explicit_k internet_exception(error_code_type err)
00141 : m_reason()
00142 , m_errorCode(err)
00143 {}
00144 internet_exception(class_type const& rhs)
00145 : m_reason(rhs.m_reason)
00146 , m_errorCode(rhs.m_errorCode)
00147 {}
00148 internet_exception(char const* reason, error_code_type err)
00149 : m_reason(class_type::create_reason_(reason, err))
00150 , m_errorCode(err)
00151 {}
00152 protected:
00153 internet_exception(string_type const& reason, error_code_type err)
00154 : m_reason(reason)
00155 , m_errorCode(err)
00156 {}
00157 public:
00163 virtual ~internet_exception() stlsoft_throw_0()
00164 {}
00166
00169 public:
00170 virtual char const* what() const stlsoft_throw_0()
00171 {
00172 if(!m_reason.empty())
00173 {
00174 return m_reason.c_str();
00175 }
00176 else
00177 {
00178 return "internet failure";
00179 }
00180 }
00181
00183 error_code_type get_error_code() const stlsoft_throw_0()
00184 {
00185 return m_errorCode;
00186 }
00190 error_code_type last_error() const stlsoft_throw_0()
00191 {
00192 return get_error_code();
00193 }
00197 error_code_type error() const stlsoft_throw_0()
00198 {
00199 return get_error_code();
00200 }
00202
00205 private:
00206 static string_type create_reason_(char const* reason, error_code_type err)
00207 {
00208 #ifdef INETSTL_OS_IS_WINDOWS
00209 if( err == static_cast<error_code_type>(E_OUTOFMEMORY) ||
00210 err == static_cast<error_code_type>(ERROR_OUTOFMEMORY) ||
00211 NULL == reason ||
00212 '\0' == reason[0])
00213 {
00214 return string_type();
00215 }
00216 else
00217 #endif
00218 {
00219 return string_type(reason);
00220 }
00221 }
00223
00226 private:
00227 const string_type m_reason;
00228 error_code_type m_errorCode;
00230
00233 private:
00234 class_type& operator =(class_type const&);
00236 };
00237
00238
00239
00240
00241
00247
00248 struct throw_internet_exception_policy
00249 {
00252 public:
00254 typedef internet_exception thrown_type;
00255 typedef internet_exception::error_code_type error_code_type;
00257
00260 public:
00262 void operator ()() const
00263 {
00264 #ifdef INETSTL_OS_IS_WINDOWS
00265 STLSOFT_THROW_X(thrown_type(::GetLastError()));
00266 #else
00267 STLSOFT_THROW_X(thrown_type(errno));
00268 #endif
00269 }
00271 void operator ()(error_code_type err) const
00272 {
00273 STLSOFT_THROW_X(thrown_type(err));
00274 }
00276 void operator ()(char const* reason, error_code_type err) const
00277 {
00278 STLSOFT_THROW_X(thrown_type(reason, err));
00279 }
00281 };
00282
00283
00284
00285 #ifndef _INETSTL_NO_NAMESPACE
00286 # if defined(_STLSOFT_NO_NAMESPACE) || \
00287 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00288 }
00289 # else
00290 }
00291 }
00292 # endif
00293 #endif
00294
00295
00296
00297 #endif
00298
00299