[GRASS-user] using try/except with grass.mapcalc in a Python Script

Jenny Turner jennyturner1980 at gmail.com
Fri Mar 11 08:12:22 EST 2011


Hello Glynn

What I want to do is run grass.mapcalc like this:
try:
   grass.mapcalc()
except:
   grass.fatal(_("An error occurred ..."))

I know that this doesn't work. What I want to catch is not "syntax" erros
but errors such as an raster input map that does not exist and is being used
in grass.mapcal should raise an error or an excpetion in order to stop the
process.

Any sugfgestions?

Thanks
Jenny

On Tue, Mar 1, 2011 at 7:26 PM, Glynn Clements <glynn at gclements.plus.com>wrote:

>
> Jenny Turner wrote:
>
> > I want to include grass.mapcalc function in try except but I'm not
> catching
> > the errors. Has anyone used this for grass.mapcalc?
>
> What sort of error are you expecting?
>
> If you call set_raise_on_error(), a non-zero exit status should raise
> a ScriptException instead of calling sys.exit() (note that sys.exit()
> raises a SystemExit exception, which can be caught if desired).
>
> Note that r.mapcalc will only return a non-zero exit status for
> fundamental errors such as syntax errors in the expression or failure
> to open a map. Calculation errors (e.g. division by zero or domain
> errors) result in null values.
>
> --
> Glynn Clements <glynn at gclements.plus.com>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20110311/792ddfab/attachment.html


More information about the grass-user mailing list