-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathException.hpp
60 lines (45 loc) · 1.51 KB
/
Exception.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
////////////////////////////////////////////////////////////////////////////////
//! \file Exception.hpp
//! \brief The Exception class declaration.
//! \author Chris Oldwood
// Check for previous inclusion
#ifndef WMI_EXCEPTION_HPP
#define WMI_EXCEPTION_HPP
#if _MSC_VER > 1000
#pragma once
#endif
#include <WCL/ComException.hpp>
namespace WMI
{
////////////////////////////////////////////////////////////////////////////////
//! The exception type thrown by the WMI library.
class Exception : public WCL::ComException
{
public:
//! Construction from a non-IErrorInfo supported error.
Exception(HRESULT result, const tchar* operation);
//! Construction from an IErrorInfo supported error.
template<typename T>
Exception(HRESULT result, WCL::IFacePtr<T>& object, const tchar* operation);
//! Destructor.
virtual ~Exception() throw();
private:
//
// Internal methods.
//
//! Format the error using the WMI or IErrorInfo details.
void formatError(HRESULT result, IUnknown* object, const IID& iid, const tchar* operation);
//! Format the WMI specific HRESULT error.
tstring formatWmiError(HRESULT error);
};
////////////////////////////////////////////////////////////////////////////////
//! Construction from an IErrorInfo supported error.
template<typename T>
inline Exception::Exception(HRESULT result, WCL::IFacePtr<T>& object, const tchar* operation)
: WCL::ComException(result)
{
formatError(result, object.get(), WCL::IFaceTraits<T>::uuidof(), operation);
}
//namespace WMI
}
#endif // WMI_EXCEPTION_HPP