added some development tools
[windows-sources.git] / developer / VSSDK / VisualStudioIntegration / Common / Source / CPP / VSL / Include / VSLExceptionHandlers.h
blob4896fd3cf84bd8fafc5be49ae380a180880825b3
1 /***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 This code is licensed under the Visual Studio SDK license terms.
5 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
10 This code is a part of the Visual Studio Library.
12 ***************************************************************************/
14 #ifndef VSLEXCEPTIONHANDLERS_H_DA737291_2E81_11D3_A504_00C04F5E0BA5
15 #define VSLEXCEPTIONHANDLERS_H_DA737291_2E81_11D3_A504_00C04F5E0BA5
17 #if _MSC_VER > 1000
18 #pragma once
19 #endif
21 #include "VSLExceptions.h"
23 namespace VSL
26 #ifndef VSL_STDMETHOD_HRESULT
27 #define VSL_STDMETHOD_HRESULT ___hr___
28 #endif // VSL_STDMETHOD_HRESULT
30 #ifndef VSL_STDMETHOD_HRESULT_INIT
31 #define VSL_STDMETHOD_HRESULT_INIT S_OK
32 #endif
34 #ifndef VSL_GET_STDMETHOD_HRESULT
35 #define VSL_GET_STDMETHOD_HRESULT() VSL_STDMETHOD_HRESULT
36 #endif // VSL_GET_STDMETHOD_HRESULT
38 #ifndef VSL_SET_STDMETHOD_HRESULT
39 #define VSL_SET_STDMETHOD_HRESULT(hr) (VSL_STDMETHOD_HRESULT = hr)
40 #endif // VSL_SET_STDMETHOD_HRESULT
42 #ifndef VSL_STDMETHODTRY_EX
43 #define VSL_STDMETHODTRY_EX(hrInit) \
44 HRESULT VSL_STDMETHOD_HRESULT = hrInit; \
45 try
46 #endif // VSL_STDMETHODTRY_EX
49 By default, VSL_STDMETHODTRY will expand to:
50 HRESULT ___hr___ = S_OK;
51 try
53 #ifndef VSL_STDMETHODTRY
54 #define VSL_STDMETHODTRY VSL_STDMETHODTRY_EX(VSL_STDMETHOD_HRESULT_INIT)
55 #endif // VSL_STDMETHODTRY
58 #ifndef VSL_STDMETHOD_ON_CATCH_CEXCEPTION
60 inline HRESULT OnCatchExceptionBase(const ExceptionBase& rException)
62 VSL_TRACE(_T("Exception caught in OnCatchExceptionBase, which is a generic exception handler, please include callstack in error report."));
64 rException.ReportError();
66 return static_cast<HRESULT>(rException);
69 #define VSL_STDMETHOD_ON_CATCH_CEXCEPTION VSL::OnCatchExceptionBase
71 #endif // VSL_STDMETHOD_ON_CATCH_CEXCEPTION
74 #ifndef VSL_STDMETHOD_ON_CATCH_STDEXCEPTION
76 inline HRESULT OnCatchStdException(const std::exception& rStdException)
78 VSL_TRACE(_T("Exception caught in OnCatchStdException, which is a generic exception handler, please include callstack in error report."));
80 ExceptionStd exception(rStdException);
82 exception.ReportError();
84 return static_cast<HRESULT>(exception);
87 #define VSL_STDMETHOD_ON_CATCH_STDEXCEPTION VSL::OnCatchStdException
89 #endif // VSL_STDMETHOD_ON_CATCH_STDEXCEPTION
91 #ifndef VSL_STDMETHOD_ON_CATCH_ATLEXCEPTION
93 inline HRESULT OnCatchAtlException(const ATL::CAtlException &rAtlException)
95 VSL_TRACE(_T("Exception caught in OnCatchAtlException, which is a generic exception handler, please include callstack in error report."));
97 VSL_REPORT_ERROR_HRESULT(static_cast<HRESULT>(rAtlException), false);
99 return static_cast<HRESULT>(rAtlException);
102 #define VSL_STDMETHOD_ON_CATCH_ATLEXCEPTION VSL::OnCatchAtlException
104 #endif // VSL_STDMETHOD_ON_CATCH_ATLEXCEPTION
106 #ifndef VSL_STDMETHOD_ON_CATCH_ALL
108 inline HRESULT OnCatchAll()
110 VSL_TRACE(_T("Exception caught in OnCatchAll, which is a generic exception handler, please include callstack in error report."));
112 return E_UNEXPECTED;
115 #define VSL_STDMETHOD_ON_CATCH_ALL VSL::OnCatchAll
117 #endif // VSL_STDMETHOD_ON_CATCH_ALL
120 #ifndef VSL_STDMETHODCATCH_EX
123 onExceptionBase: defined to accept a ExceptionBase and evalutuate to an HRESULT
124 onStdException: defined to accept a std::exception and evalutuate to an HRESULT
125 onCatchAll: defined to accept no parameters and evalutuate to an HRESULT
128 #define VSL_STDMETHODCATCH_EX(onExceptionBase, onStdException, onCatchAll) \
129 catch(const VSL::ExceptionBase &rException) \
131 VSL_SET_STDMETHOD_HRESULT(VSL_STDMETHOD_ON_CATCH_CEXCEPTION(rException)); \
133 catch(const std::exception &rStdException) \
135 VSL_SET_STDMETHOD_HRESULT(VSL_STDMETHOD_ON_CATCH_STDEXCEPTION(rStdException)); \
137 catch(const ATL::CAtlException &rAtlException) \
139 VSL_SET_STDMETHOD_HRESULT(VSL_STDMETHOD_ON_CATCH_ATLEXCEPTION(rAtlException)); \
141 catch(...) \
143 VSL_SET_STDMETHOD_HRESULT(onCatchAll()); \
146 #endif // VSL_STDMETHODCATCH_EX
149 #ifndef VSL_STDMETHODCATCH
150 #define VSL_STDMETHODCATCH() VSL_STDMETHODCATCH_EX(VSL_STDMETHOD_ON_CATCH_CEXCEPTION, VSL_STDMETHOD_ON_CATCH_STDEXCEPTION, VSL_STDMETHOD_ON_CATCH_ALL)
151 #endif // VSL_STDMETHODCATCH
153 } // namespace VSL
155 #endif // VSLEXCEPTIONHANDLERS_H_DA737291_2E81_11D3_A504_00C04F5E0BA5