[Mobies-commit] [commit] r3621 - UDM/trunk/src/UdmGme
ksmyth at redhat1.isis.vanderbilt.edu
ksmyth at redhat1.isis.vanderbilt.edu
Fri Jan 28 15:58:56 CST 2011
Author: ksmyth
Date: Fri Jan 28 15:58:56 2011
New Revision: 3621
Log:
Use _set_com_error_handler for proper error handling. e.g. E_POINTER exceptions werent being translated to udm_exceptions
Modified:
UDM/trunk/src/UdmGme/GmeObject.h
UDM/trunk/src/UdmGme/UdmGme.cpp
Modified: UDM/trunk/src/UdmGme/GmeObject.h
==============================================================================
--- UDM/trunk/src/UdmGme/GmeObject.h Fri Jan 28 15:57:50 2011 (r3620)
+++ UDM/trunk/src/UdmGme/GmeObject.h Fri Jan 28 15:58:56 2011 (r3621)
@@ -45,6 +45,7 @@
static gdnmap GDNMap;
+ void com_exception(HRESULT a, IErrorInfo *errorinfo);
void com_exception(HRESULT a, IUnknown *b, REFIID c);
string getnameforassoc(const ::Uml::Association &ass, bool generate_name);
Modified: UDM/trunk/src/UdmGme/UdmGme.cpp
==============================================================================
--- UDM/trunk/src/UdmGme/UdmGme.cpp Fri Jan 28 15:57:50 2011 (r3620)
+++ UDM/trunk/src/UdmGme/UdmGme.cpp Fri Jan 28 15:58:56 2011 (r3621)
@@ -237,6 +237,8 @@
#include "GmeObject.h"
#include <UdmUtil.h>
+#include <sstream>
+
// Hack to detect VS10 GME: VS10 GME has ifdef guards in InterfaceVersion.h
#define INTERFACEVERSION_INCLUDED
#define cpp_quote(x) namespace { }
@@ -292,27 +294,52 @@
IMgaTerritoryPtr terr;
};
+ void com_exception(HRESULT a, IErrorInfo* errorinfo) {
+ std::stringstream error_message;
+ SmartBSTR str;
+ if (errorinfo != 0) {
+ BSTR bbstr;
+ if (SUCCEEDED(errorinfo->GetDescription(&bbstr))) {
+ str.Attach(bbstr);
+ }
+ }
+ if (!str) {
+ LPTSTR errorText = NULL;
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, a, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&errorText, 0, NULL);
+ if (errorText != NULL) {
+ str = errorText;
+ LocalFree(errorText);
+ }
+ }
+ error_message << "Com exception: ";
+ if (!!str) {
+ error_message << static_cast<const char*>(str);
+ error_message << " (0x" << std::hex << setw(8) << (unsigned long)a << ")";
+ } else {
+ error_message << "0x" << std::hex << setw(8) << (unsigned long)a;
+ }
+
+ throw udm_exception(error_message.str());
+ }
+
void com_exception(HRESULT a, IUnknown *b, REFIID c)
{
- char s[100];
- ISupportErrorInfoPtr pp = b;
- SmartBSTR str;
- if(pp)
- {
- if(pp->InterfaceSupportsErrorInfo(c) == S_OK)
+ if (b) {
+ ISupportErrorInfoPtr pp = b;
+ if(pp)
{
- IErrorInfoPtr ee;
- GetErrorInfo(0, &ee);
- BSTR bbstr;
- ee->GetDescription(&bbstr);
- str = bbstr;
- SysFreeString(bbstr);
+ if(pp->InterfaceSupportsErrorInfo(c) == S_OK)
+ {
+ IErrorInfoPtr ee;
+ if (SUCCEEDED(GetErrorInfo(0, &ee))) {
+ com_exception(a, ee);
+ }
+ }
}
}
- if(!!str) sprintf(s, "Com exception: %S\n", (BSTR)str);
- else sprintf(s, "Com exception: #%08X\n", a);
-
- throw udm_exception(s);
+ com_exception(a, NULL);
}
SmartBSTR createGMEconnstr(string sn);
@@ -847,6 +874,7 @@
Argh! COM pointers to the same object ain't the same!
if(static_cast<GmeObject *>(*i)->self == static_cast<GmeObject *>(*j)->self)
*/
+ // FIXME: this will crash if i or j are from the wrong DataNetwork and are not GmeObjects
IMgaFCOPtr n21 = static_cast<GmeObject *>(*i)->self;
IMgaFCOPtr n22 = static_cast<GmeObject *>(*j)->self;
VARIANT_BOOL n = n21->GetIsEqual(n22);
@@ -2640,6 +2668,7 @@
mydn = dn;
#ifdef _DEBUG
name = (const char*)obj->GetName();
+ uniqueId();
#endif
};
@@ -2651,6 +2680,7 @@
m_type = findClass();
#ifdef _DEBUG
name = (const char*)obj->GetName();
+ uniqueId();
#endif
if (!mydn) throw udm_exception("Data Network is NULL in constructor! GmeObject without a data network ?!");
};
@@ -2661,6 +2691,7 @@
mydn = dn;
#ifdef _DEBUG
name = (const char*)obj->GetName();
+ uniqueId();
#endif
if (!mydn) throw udm_exception("Data Network is NULL in constructor! GmeObject without a data network ?!");
};
@@ -2673,6 +2704,7 @@
m_type = findClass();
#ifdef _DEBUG
name = (const char*)obj->GetName();
+ uniqueId();
#endif
if (!mydn) throw udm_exception("Data Network is NULL in constructor! GmeObject without a data network ?!");
};
@@ -3875,15 +3907,18 @@
return MetaRoleFilter;
}
-
-
+ __declspec(noreturn) static void __stdcall _udmgme_com_raise_error(HRESULT hr, IErrorInfo* errorinfo) {
+ com_exception(hr, errorinfo);
+ }
static class reg {
public:
reg() {
GmeDataNetwork::RegisterBackend("GME", "mga", &GmeDataNetwork::factory);
+ _set_com_error_handler(_udmgme_com_raise_error);
}
~reg() {
GmeDataNetwork::UnRegisterBackends();
+ _set_com_error_handler(_com_raise_error);
}
} _reg_unused;
More information about the Mobies-commit
mailing list