DynamoDS/DynamoRevit — pull request #49 by Randy-Ma (2014-12-08 09:34:44+00:00)
Title: Hanlding exceptions when constructing elements

Summary

When constructing elements, there may be exceptions thrown and then the half-constructed elements may be registered with the life cycle manager. This will cause:
1). The half-constructed elements will never be disposed by us because they are half-constructed;
2). In the case, the element ID is registered with the life cycle manager, the related Revit element will not be deleted.

In this submission, I am making the fix by implement a SafeInit method in the Element class to run an action and catch possible exceptions thrown. If there are any exceptions and if the object has been registered with the life cycle manager, the object will be unregisted.

Then in the derived classes, I am separating the constructors into init functions which take the same parameters as the constructors, and the constructors will call the SafeInit method which will take the init functions as input.

@pboyer
PTAL