[Mobies-commit] [commit] r3832 - UDM/trunk/src/UdmGme

ksmyth at redhat1.isis.vanderbilt.edu ksmyth at redhat1.isis.vanderbilt.edu
Fri Aug 19 11:12:47 CDT 2011


Author: ksmyth
Date: Fri Aug 19 11:12:46 2011
New Revision: 3832

Log:
Clean up error handling

Modified:
   UDM/trunk/src/UdmGme/CommonHeaders.h
   UDM/trunk/src/UdmGme/MgaDefs.h
   UDM/trunk/src/UdmGme/UdmGme.cpp

Modified: UDM/trunk/src/UdmGme/CommonHeaders.h
==============================================================================
--- UDM/trunk/src/UdmGme/CommonHeaders.h	Fri Aug 19 10:43:20 2011	(r3831)
+++ UDM/trunk/src/UdmGme/CommonHeaders.h	Fri Aug 19 11:12:46 2011	(r3832)
@@ -33,6 +33,7 @@
 namespace UdmGme
 {
 	void com_exception(HRESULT a, IUnknown *b, REFIID c);
+	void com_exception(HRESULT a, IErrorInfo *errorinfo);
 };
 
 

Modified: UDM/trunk/src/UdmGme/MgaDefs.h
==============================================================================
--- UDM/trunk/src/UdmGme/MgaDefs.h	Fri Aug 19 10:43:20 2011	(r3831)
+++ UDM/trunk/src/UdmGme/MgaDefs.h	Fri Aug 19 11:12:46 2011	(r3832)
@@ -32,11 +32,8 @@
 
 //so-called error handling 
 
-void SetErrorInfo(long,unsigned short *) { UDM_ASSERT("NotYet Implemented"); }
 void comthrow(HRESULT res, char *e, int l);
 #define COMTHROW(expr) comthrow(expr, #expr, __LINE__)
-#define CASSERT(x) if(!(x)) COMTHROW( ((x), -1))
-
 
 class gme_exc : public udm_exception 
 { 
@@ -48,12 +45,13 @@
 
 static void comthrow(HRESULT res, char *e, int l) 
 {
-	if ((res) != S_OK) throw gme_exc(res);
+	if (FAILED(res))
+		UdmGme::com_exception(res, NULL);
 }
 
 //GmeObject class helper macros
 #define objself (folderself? (IMgaObject *) folderself : (IMgaObject *)self)
-#define testself (self ? self : (COMTHROW(("Invalid method on folders", -1)), NULL))
+#define testself (self ? self : (throw udm_exception("Invalid method on folders"), NULL))
 #define NAMEGET(x) (((string)((x).name())).c_str())
 #define PATHGET(x) (((x).getPath2("::", false)).c_str())
 #define foldiffold (folderself ? folderself : self)

Modified: UDM/trunk/src/UdmGme/UdmGme.cpp
==============================================================================
--- UDM/trunk/src/UdmGme/UdmGme.cpp	Fri Aug 19 10:43:20 2011	(r3831)
+++ UDM/trunk/src/UdmGme/UdmGme.cpp	Fri Aug 19 11:12:46 2011	(r3832)
@@ -1673,7 +1673,8 @@
 			
 			if(mf) 
 			{
-				if(mfco) CASSERT("Multiple child kinds match");
+				if(mfco)
+					throw udm_exception("Multiple child kinds match");
 				IMgaFolderPtr nf;
 				nf = folderself->CreateFolder(mf);
 				GmeObject * retval = new GmeObject( nf, mydn);
@@ -1706,8 +1707,7 @@
 		IMgaModelPtr m = self;
 		IMgaMetaModelPtr pmeta = Meta();
 		if(m == NULL || pmeta == NULL) 
-			// throw udm_exception("Not a model");
-			COMTHROW(("Not a model", 1));
+			throw udm_exception("Not a model");
 		IMgaMetaRolePtr rr;
 		if(role) 
 		{
@@ -1783,7 +1783,8 @@
 		((GmeDataNetwork*)mydn)->CountWriteOps();
 
 		IMgaModelPtr parent = self;
-		if(parent == NULL) COMTHROW(("No parent or non-model parent specified", 1));
+		if(parent == NULL) 
+			throw udm_exception("No parent or non-model parent specified");
 		
 		vector<ObjectImpl*> aa = a;
 		IMgaMetaRolePtr rr;
@@ -2011,13 +2012,15 @@
 			return;
 		}
 		parent = static_cast<GmeObject *>(a)->self;
-		if(parent == NULL) COMTHROW(("No parent or non-model parent specified", 1));
+		if(parent == NULL)
+			throw udm_exception("No parent or non-model parent specified");
 
 		IMgaMetaRolePtr rr;
 		if(role)  
 		{
 			rr = GetMetaRoleForChildRole(Uml::theOther(role), parent->Meta);
-			if(CompareKindToClass(rr->kind, m_type)) CASSERT("Role-Kindname mismatch");
+			if(CompareKindToClass(rr->kind, m_type))
+				throw udm_exception("Role-Kindname mismatch");
 		}
 #ifndef DEDUCE_NULLROLES
 		else 
@@ -2041,7 +2044,8 @@
 				}
 			} 
 			MGACOLL_ITERATE_END;
-			if(rr == NULL) CASSERT("Parent cannot have this child");
+			if(rr == NULL)
+				throw udm_exception("Parent cannot have this child");
 		}
 #endif
 		IMgaFCOsPtr fcos;
@@ -2593,7 +2597,7 @@
 		if(swscanf(gmeId, OLESTR("id-%04lx-%08lx"), &c, &p) != 2 ||
 			(c-=100) > OBJTYPE_FOLDER || c < OBJTYPE_MODEL || p > 100000000) 
 		{
-			COMTHROW(("OBJID too big or invalid", 1));
+			throw udm_exception("OBJID too big or invalid");
 		}
 		return 100000000 * c + p;
 	}
@@ -2603,7 +2607,7 @@
 		if(sscanf(gmeId, "id-%04lx-%08lx", &c, &p) != 2 ||
 			(c-=100) > OBJTYPE_FOLDER || c < OBJTYPE_MODEL || p > 100000000) 
 		{
-			COMTHROW(("OBJID too big or invalid", 1));
+			throw udm_exception("OBJID too big or invalid");
 		}
 		return 100000000 * c + p;
 	}
@@ -3660,12 +3664,12 @@
 		semantics = sem;
 		hasOpened=true;
 		IMgaProjectPtr  &project = priv.project;
-		project.Attach((IMgaProject *)pUnknown, true);
+		project = pUnknown;
 
 		if (customtransactions) {
 			priv.terr = 0;
 		} else {
-			COMTHROW(project->CreateTerritory(NULL, &priv.terr, NULL));
+			project->CreateTerritory(NULL, &priv.terr, NULL);
 		}
 
 		// For write
@@ -3673,20 +3677,20 @@
 
 
 		if (priv.terr)
-			COMTHROW(project->BeginTransaction(priv.terr, TRANSACTION_GENERAL));
+			project->BeginTransaction(priv.terr, TRANSACTION_GENERAL);
 		try {
 			amapInitialize(GetRootMeta(), project->RootMeta);
 // get rootfolder & get name
 
 			rootobject = new GmeObject( project->RootFolder, this);
 		}
-		catch(gme_exc &s) { 
+		catch(udm_exception &s) { 
 			amapClear(amap);
 			if (priv.terr) {
-				COMTHROW(project->AbortTransaction());
-				COMTHROW(priv.terr->Destroy());
+				project->AbortTransaction();
+				priv.terr->Destroy();
 			}
-			COMTHROW(project->Close(VARIANT_TRUE));
+			project->Close(VARIANT_TRUE);
 			throw s;
 		}
 
@@ -3722,7 +3726,7 @@
 // get rootfolder & get name
 			rootobject = new GmeObject( project->RootFolder, this );
 		}
-		catch(gme_exc &s) { 
+		catch(udm_exception &s) { 
 			amapClear(amap);
 			COMTHROW(project->AbortTransaction());
 			COMTHROW(priv.terr->Destroy());
@@ -3757,12 +3761,12 @@
 			if(bb->m_type != rootclass) 
 			{
 				delete bb;
-				CASSERT("Cannot create this object as root");
+				throw udm_exception("Cannot create this object as root");
 			}
 
 			rootobject = bb;
 		}
-		catch(gme_exc &s) { 
+		catch(udm_exception &s) { 
 			amapClear(amap);
 			COMTHROW(project->AbortTransaction());
 			COMTHROW(priv.terr->Destroy());


More information about the Mobies-commit mailing list