diff --git a/include/WinStd/COM.h b/include/WinStd/COM.h index bf617ab2..26a1f15b 100644 --- a/include/WinStd/COM.h +++ b/include/WinStd/COM.h @@ -29,19 +29,7 @@ namespace winstd class WINSTD_API bstr; class WINSTD_API variant; class WINSTD_API com_initializer; - - /// - /// \defgroup WinStdExceptions Exceptions - /// Additional exceptions - /// - /// @{ - - /// - /// COM runtime error - /// - typedef num_runtime_error com_runtime_error; - - /// @} + class WINSTD_API com_runtime_error; } #pragma once @@ -975,4 +963,53 @@ namespace winstd protected: HRESULT m_result; ///< Result of CoInitialize call }; + + + /// + /// \defgroup WinStdExceptions Exceptions + /// Additional exceptions + /// + /// @{ + + /// + /// COM runtime error + /// + /// \note Must be defined as derived class from num_runtime_error<> to allow correct type info for dynamic typecasting and prevent folding with other derivates of num_runtime_error<>. + /// + class WINSTD_API com_runtime_error : public num_runtime_error + { + public: + /// + /// Constructs an exception + /// + /// \param[in] error COM error code + /// \param[in] msg Error message + /// + inline com_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg.c_str()) + { + } + + + /// + /// Constructs an exception + /// + /// \param[in] num COM error code + /// \param[in] msg Error message + /// + inline com_runtime_error(_In_ error_type num, _In_z_ const char *msg) : num_runtime_error(num, msg) + { + } + + + /// + /// Copies an exception + /// + /// \param[in] other Exception to copy from + /// + inline com_runtime_error(const com_runtime_error &other) : num_runtime_error(other) + { + } + }; + + /// @} } diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index 61e9e454..5d5cefdb 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -702,7 +702,7 @@ namespace winstd /// @{ /// - /// Windows runtime error + /// Numerical runtime error /// template class num_runtime_error : public std::runtime_error @@ -798,7 +798,7 @@ namespace winstd /// /// Constructs an exception /// - /// \param[in] num Numeric error code + /// \param[in] num Windows error code /// \param[in] msg Error message /// inline win_runtime_error(_In_ error_type num, _In_z_ const char *msg) : num_runtime_error(num, msg) diff --git a/include/WinStd/Sec.h b/include/WinStd/Sec.h index 55e862f2..6f1b9c70 100644 --- a/include/WinStd/Sec.h +++ b/include/WinStd/Sec.h @@ -31,19 +31,7 @@ namespace winstd class WINSTD_API sec_credentials; class WINSTD_API sec_context; class WINSTD_API sec_buffer_desc; - - /// - /// \defgroup WinStdExceptions Exceptions - /// Additional exceptions - /// - /// @{ - - /// - /// COM runtime error - /// - typedef num_runtime_error sec_runtime_error; - - /// @} + class WINSTD_API sec_runtime_error; } #pragma once @@ -358,4 +346,53 @@ namespace winstd }; /// @} + + + /// + /// \defgroup WinStdExceptions Exceptions + /// Additional exceptions + /// + /// @{ + + /// + /// COM runtime error + /// + /// \note Must be defined as derived class from num_runtime_error<> to allow correct type info for dynamic typecasting and prevent folding with other derivates of num_runtime_error<>. + /// + class WINSTD_API sec_runtime_error : public num_runtime_error + { + public: + /// + /// Constructs an exception + /// + /// \param[in] error Security provider error code + /// \param[in] msg Error message + /// + inline sec_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg.c_str()) + { + } + + + /// + /// Constructs an exception + /// + /// \param[in] num Security provider error code + /// \param[in] msg Error message + /// + inline sec_runtime_error(_In_ error_type num, _In_z_ const char *msg) : num_runtime_error(num, msg) + { + } + + + /// + /// Copies an exception + /// + /// \param[in] other Exception to copy from + /// + inline sec_runtime_error(const sec_runtime_error &other) : num_runtime_error(other) + { + } + }; + + /// @} }