DevonTaig

Proper use of IEditor (StartOperation / StopOperation)

Discussion created by DevonTaig on Mar 16, 2011
Latest reply on May 10, 2011 by agray1
I'm having some problems getting IEditor to behave in a stable manner.  If everything goes right in my code, then all is good, but if something unexpected happens (e.g. try to put too much data into a small field) it screws up the editor operation stack (I think) and then I basically need to restart ArcMap. It seems like I might get errors when I call Store, StartOperation, or even StopOperation. It kinda seems to vary. QUESTION: How can I rewrite the code below to keep things in a good state if something unexpected happens? Is there some key method like IsInEditOperation that I am missing as part of good defensive coding techniques.

Essentially my code looks like this:

bool hadToStartEditing = false;
if(editor.EditState == esriStateNotEditing)
{
  editor.StartEditing();
  hadToStartEditing = true;
}
editor.StartOperation();
//...More code to create a new feature & set it's shape / subype
// ...More code to set values on various fields (hopefully legal values, but perhaps not always)
editor.StopOperation();
if(hadToStartEditing)
{
  editor.StopEditing(True);
}

Outcomes