gracecai

Using Try/Catch to resolve error thrown when reclassifying a non-existent value

Discussion created by gracecai on Aug 1, 2012
Latest reply on Aug 2, 2012 by Neil
Hi,

When I try to reclassify a value using IReclassOp.ReclassByRemap and if none of the values/ranges in the reclass table exist in the input raster I get this error:

ERROR 010067: Error in executing grid expression. Unable to initialize reclass table...

So instead of checking if a certain value exists I've put the reclass code in a try/catch block to handle the problem. I know this isn't really the ideal way of using try/catch but I can't find any efficient solution to this problem. I'd love to hear your opinion. If anyone knows of a better solution please let me know!

            
            try
            {
                IReclassOp reclassOp = new RasterReclassOpClass();
                INumberRemap remapHardZero = new NumberRemapClass();
                remapHardZero.MapValueToNoData(0.0);
                inputDataset = reclassOp.ReclassByRemap(inputDataset, remapHardZero as IRemap, true);
                return inputDataset;
            }

            catch (Exception err)
            {
                if (!Regex.IsMatch(err.ToString(), "ERROR 010067: Error in executing grid expression. Unable to initialize reclass table"))
                { MessageBox.Show(err.ToString()); }
                return null;
            }

Outcomes