1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4// ---------------------------------------------------------------------------
5// COMEx.cpp
6//
7
8//
9// ---------------------------------------------------------------------------
10
11#include "stdafx.h"
12#include "string.h"
13#include "ex.h"
14#include "holder.h"
15#include "corerror.h"
16
17// ---------------------------------------------------------------------------
18// COMException class. Implements exception API for standard COM-based error info
19// ---------------------------------------------------------------------------
20
21COMException::~COMException()
22{
23 WRAPPER_NO_CONTRACT;
24
25 if (m_pErrorInfo != NULL)
26 m_pErrorInfo->Release();
27}
28
29IErrorInfo *COMException::GetErrorInfo()
30{
31 LIMITED_METHOD_CONTRACT;
32
33 IErrorInfo *pErrorInfo = m_pErrorInfo;
34 if (pErrorInfo != NULL)
35 pErrorInfo->AddRef();
36 return pErrorInfo;
37}
38
39void COMException::GetMessage(SString &string)
40{
41 STATIC_CONTRACT_THROWS;
42 STATIC_CONTRACT_GC_NOTRIGGER;
43
44 if (m_pErrorInfo != NULL)
45 {
46 BSTRHolder message(NULL);
47 if (SUCCEEDED(m_pErrorInfo->GetDescription(&message)))
48 string.Set(message, SysStringLen(message));
49 }
50}
51
52