cpicciri

Best ArcObjects error handler

Discussion created by cpicciri on Jan 23, 2012
Latest reply on Jan 23, 2012 by cpicciri
Hi everyone,

This is more of a .NET question than an ArcObjects question so my apologies for posting here but the IT department of my company has the Internet locked down quite tightly where all discussion groups are automatically blocked and unfortunately, most coding sites fall into this category. The only reason I can get to the ESRI forums is because the site belongs to ESRI and we have lots of ArcGIS licenses.

I'm hoping someone can provide me with an answer or at least point me in the right direction.

I am developing in C# using .NET 4.0 and ArcGIS 9.3 but I'm pretty sure I can convert code samples in almost any language.

For the sake of simplicity, say you have two procedures, 1 and 2. Procedure 1 does some processing calls procedure 2 and when control returns to procedure 1, it takes the output from procedure 2 and does some additional processing.

My problem occurs when procedure 2 has an issue (crashes) and control returns to procedure 1. I have error handlers in all of my procedures and they are all like this:

public static void ApplyDefinitionQuery(IFeatureLayer featureLayer, string definitionQuery)
{
    IFeatureLayerDefinition pFeatureLayerDefinition = null;

    try
    {
 pFeatureLayerDefinition = featureLayer as IFeatureLayerDefinition;
 pFeatureLayerDefinition.DefinitionExpression = definitionQuery;
    }
    catch (Exception ex)
    {
 ClsLogErrors.LogError(ex.StackTrace, ex.Message, "ApplyDefinitionQuery", null);
 MessageBox.Show("The RegGSS Extension encountered a problem." + "\r\n" + "The Regulatory GIS Section has been notified.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    finally
    {
        if (pFeatureLayerDefinition != null) { Marshal.ReleaseComObject(pFeatureLayerDefinition); pFeatureLayerDefinition = null; }
    }
}


If procedure 2 crashes, the error handler catches the error and writes it out to a database for later debugging. This all works fine. Problem is, if procedure 2 crashes, I don't want procedure 1 to continue when control returns to it. How can I get all the code to stop executing if procedure 2 bombs? The only way I can think of doing it is to make Procedure 2 return a boolean depending on if it succeded or not. However, this becomes a problem too because the majority of our procedures already return something, array, string, etc. and as far as I know, you cannot return more than one value from a procedure.

Hope this makes sense.

Thanks for your time.

Carlos

Outcomes