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
00051 #ifndef COMSTL_INCL_COMSTL_ERROR_HPP_EXCEPTIONS
00052 #define COMSTL_INCL_COMSTL_ERROR_HPP_EXCEPTIONS
00053
00054 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00055 # define COMSTL_VER_COMSTL_ERROR_HPP_EXCEPTIONS_MAJOR 2
00056 # define COMSTL_VER_COMSTL_ERROR_HPP_EXCEPTIONS_MINOR 2
00057 # define COMSTL_VER_COMSTL_ERROR_HPP_EXCEPTIONS_REVISION 1
00058 # define COMSTL_VER_COMSTL_ERROR_HPP_EXCEPTIONS_EDIT 44
00059 #endif
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #ifndef COMSTL_INCL_COMSTL_H_COMSTL
00074 # include <comstl/comstl.h>
00075 #endif
00076 #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_PROJECT_EXCEPTION
00077 # include <stlsoft/error/project_exception.hpp>
00078 #endif
00079 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_EXCEPTION_STRING
00080 # include <stlsoft/util/exception_string.hpp>
00081 #endif
00082
00083
00084
00085
00086
00087 #ifndef _COMSTL_NO_NAMESPACE
00088 # if defined(_STLSOFT_NO_NAMESPACE) || \
00089 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00090
00091 namespace comstl
00092 {
00093 # else
00094
00095
00096 namespace stlsoft
00097 {
00098
00099 namespace comstl_project
00100 {
00101
00102 # endif
00103 #endif
00104
00105
00106
00107
00108
00114 class com_exception
00115 : public stlsoft_ns_qual(project_exception)
00116 {
00119 private:
00120 typedef stlsoft_ns_qual(exception_string) string_type;
00121 public:
00122 typedef com_exception class_type;
00123 typedef stlsoft_ns_qual(project_exception) parent_class_type;
00125
00128 public:
00132 ss_explicit_k com_exception(HRESULT hr)
00133 : m_reason()
00134 , m_hr(hr)
00135 {}
00140 com_exception(char const* reason, HRESULT hr)
00141 : m_reason((NULL == reason) ? "" : reason)
00142 , m_hr(hr)
00143 {}
00149 virtual ~com_exception() stlsoft_throw_0()
00150 {}
00152
00155 public:
00156 virtual char const* what() const stlsoft_throw_0()
00157 {
00158 return m_reason.empty() ? this->real_what_(): m_reason.c_str();
00159 }
00160
00162 HRESULT get_hr() const
00163 {
00164 return m_hr;
00165 }
00166
00170 HRESULT hr() const
00171 {
00172 return m_hr;
00173 }
00175
00178 private:
00179 virtual char const* real_what_() const throw()
00180 {
00181 return "COM exception";
00182 }
00184
00187 private:
00188 string_type m_reason;
00189 HRESULT m_hr;
00191
00194 private:
00195 class_type& operator =(class_type const&);
00197 };
00198
00206 class variant_type_exception
00207 : public com_exception
00208 {
00209 public:
00210 typedef com_exception parent_class_type;
00211 typedef variant_type_exception class_type;
00212
00215 public:
00216 ss_explicit_k variant_type_exception(HRESULT hr)
00217 : parent_class_type(hr)
00218 {}
00219 variant_type_exception(char const* reason, HRESULT hr)
00220 : parent_class_type(reason, hr)
00221 {}
00227 virtual ~variant_type_exception() stlsoft_throw_0()
00228 {}
00230
00233 private:
00234 virtual char const* real_what_() const throw()
00235 {
00236 return "VARIANT type exception";
00237 }
00239 };
00240
00241
00242
00243
00244
00250 template <ss_typename_param_k X>
00251
00252 struct exception_policy_base
00253 {
00256 public:
00258 typedef X thrown_type;
00260
00263 public:
00265 void operator ()() const
00266 {
00267 STLSOFT_THROW_X(thrown_type(::GetLastError()));
00268 }
00270 void operator ()(HRESULT hr) const
00271 {
00272 STLSOFT_THROW_X(thrown_type(hr));
00273 }
00275 void operator ()(char const* reason, HRESULT hr) const
00276 {
00277 STLSOFT_THROW_X(thrown_type(reason, hr));
00278 }
00280 };
00281
00287 typedef exception_policy_base<com_exception> com_exception_policy;
00288
00294 typedef exception_policy_base<variant_type_exception> variant_type_exception_policy;
00295
00297
00298
00299 #ifdef STLSOFT_UNITTEST
00300 # include "./unittest/exceptions_unittest_.h"
00301 #endif
00302
00303
00304
00305 #ifndef _COMSTL_NO_NAMESPACE
00306 # if defined(_STLSOFT_NO_NAMESPACE) || \
00307 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00308 }
00309 # else
00310 }
00311 }
00312 # endif
00313 #endif
00314
00315
00316
00317 #endif
00318
00319