[GRASS-dev] Re: [GRASS-user] Catch errors from grass.mapcalc

Glynn Clements glynn at gclements.plus.com
Fri Oct 29 22:56:50 EDT 2010


Kim Besson wrote:

> I have  python script where I try to catch, as much as possible all errors,
> in order to avoid "abrupt" ERRORS from the script.
> for instance I do this for grass.run_command:
> 
> p=grass.run_command("i.group", group=group_name, subgroup="subgroup", input=
> input)
>     if p!=0:
>        grass.fatal(_("ERROR MESSAGE"))
> 
> but I'm not being able to do this for grass.mapcalc. has anyone any
> suggestion or tip on how to do this for grass.mapcalc?

You could probably replace the imported fatal() function with your own
function, e.g.:

	import grass.script as grass
	...
	def my_fatal(msg):
		...

	grass.raster.fatal = my_fatal

Beyond that, we should probably think about how to deal with errors in
the Python scripting library. I.e. whether to raise Python exceptions,
return status codes, call fatal(), etc. Right now, each function does
as it pleases; there isn't any consistency.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list