2

I need to abort an edit operation somewhere, determined by a certain condition.

Heres the code I'm using:

    private const int E_FAIL = -2147467259;

    private void _Events_OnDeleteFeature(IObject obj)
    {
        _logger.Info("Iniciando handler de OnDeleteFeature...");
        try
        {
            // do we need to abort it?
            // this method returns a COMException with code = E_FAIL; 
            if (DoINeedToAbort(obj, geaEditOperation.DELETE))
                return;
        }
        catch (COMException comEx)
        {
            throw comEx;
        }
    }

This is not showing me the appropriate message and it's not aborting the operation. BTW, this event is a IEditEvent, and it's being fired ok. The problem is to abort the operation, without calling _editor.AbortEditOperation(), which gives me an ugly message.

This is where I looked it in ESRIs manual (I know that the following applies to class extensions)

http://resources.esri.com/help/9.3/arcgisengine/ArcObjects/ao_start.htm#esriGeodatabase/IObjectClassEvents.htm

Any tips?

  • Why are you returning from your handler when DoINeedToAbort returns true? Does DoINeedToAbort throw an exception or merely return a boolean? Is the exception ever thrown? Also the immediate rethrow (which should actually be just "throw;" instead of "throw comEx;", the latter loses your exception stack trace) is a bit confusing. – Petr Krebs May 12 '11 at 20:32
  • Thanks for your input Petr. I'll try to refactor the code to a more simplistic approach and try again! – George Silva May 13 '11 at 12:47
1

I am not sure if I understand your problem correctly, but when throwing COM exceptions, it is generally best to use the COMException constructor overload which allows you to set both error message and error code.

Throwing the exception with E_FAIL error code is then something along those lines:

throw new COMException("Error", E_FAIL);
  • My problem is that ESRI manual states that a certain COMException with a certain code, should cause ArcMap to abort an edit operation which it does not. Down at DoINeedToAbort method I use that overloaded constructor to set both the message and code. The message does not display and the abort operation call does NOT happen :( – George Silva May 12 '11 at 20:10
1

According to the documentation on editor events, Managing edit sessions and edit operations, it says "Currently, there is no opportunity to abort the edit operation. Do not call AbortOperation inside any editor event, including BeforeStopOperation."

So the answer is you need to do it in an ObjectClass event.

  • Hello Alex, thank you for registering your answer here. I painfully discovered that the Editor events DO NOT capture COMExceptions like IObjectClassEvents does. Thanks! – George Silva Jun 30 '11 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.