Since you have the transaction wrapped in a ‘using ‘ statement, the transaction will be disposed of once it goes out of scope, even if there is an exception.
One of the things I have been wondering about is, do I need to make sure that my newly created objects are disposed of in the case of an exception before the call to commit? If so maybe it might be better to throw an exception rather than just using return, at least I would have a chance to dispose of the objects. Consider this example
namespace ExecMethod
{
public class Commands
{
[CommandMethod("doit")]
static public void doit()
{
Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
bool errorFlag = false;
Line ln = new Line(new Point3d(0, 0, 0), new Point3d(100, 0, 0));
try
{
AcDb.TransactionManager manager = db.TransactionManager;
using (Transaction transaction = manager.StartTransaction())
{
BlockTableRecord record = (BlockTableRecord)transaction.GetObject
(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite, false);
record.AppendEntity(ln);
transaction.AddNewlyCreatedDBObject(ln, true);
errorFlag = true; // Oh No
if (errorFlag)
{
throw new System.InvalidOperationException();
}
transaction.Commit();
}
}
catch (System.InvalidOperationException ex)
{
ed.WriteMessage("\nHere in this Exception we can clean up ln\n");
ed.WriteMessage(ex.Message);
ed.WriteMessage(ex.StackTrace);
ln.Dispose(); //<---- Dispose
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
ed.WriteMessage(ex.StackTrace);
}
}
}
}
Edit; in your example, the transaction would be aborted, if something went wrong