Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
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 May 13 '11 at 12:47
add comment

2 Answers

up vote 1 down vote accepted

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);
share|improve this answer
    
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 May 12 '11 at 20:10
add comment

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.

share|improve this answer
    
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 Jun 30 '11 at 19:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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