Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MattAdamson on October 05, 2006, 03:00:22 am
-
Guys,
I'm not overly happy with the inconsistent in the object model between methods throwing exceptions or using return values e.g. many Update methods contain a boolean flag. If this fails the documentation indicates GetLastError should be called to extract the error.
I've never had an issue with Update methods failed, only exceptions raised until now. I have the following code
EA.Connector sourceElementConnector = (EA.Connector)sourceElement.Connectors.AddNew("",
"Association");
sourceElementConnector.SupplierID = ((EA.Element)targetElement).ElementID;
sourceElementConnector.Stereotype = stereotype;
if(sourceElementConnector.Update())
{
throw new ApplicationException(String.Format("Failed to associate elements and update source connector for source element name='{0}' Err='{1}'",
sourceElement.Name,
sourceElementConnector.GetLastError()));
Has anyone else had this issue, is there any other way to extract error information here. Should I be accessing the GetLastError method on another object other than the one for which the Update method failed.
-
:-[, if checking Update should be ! Update
-
Is the issue that GetLastError() on the element is returning an empty string... or are just generally annoyed with the inconsistency of the model ;)
-
Inconsistency, i.e. having to check the return value and whether an exception is thrown.
-
Yeah, the inconsitences are anoying - I've written a managed wrapper over the top of the EA COM components I work with to shield me from some of this stuff..
In some rate situations it may be more efficient to have boolean flags returned though (ie. if your looping through a number of tasks in an add-in and want to accumulate failure information, as opposed to imediately bailing out - the cost of raising exceptions, especially across the managed/unmanaged boundry can be time consuming).