Hi
I am fairly new to both Python and Grass...
I am trying to catch exceptions thrown up by GRASS using try/except but
can't seem to get it working!
For example
try:
grass.run_command('v.in.ogr', dsn=sLayer, output=sLayerName, quiet=True)
except:
...
With the above I am trying to load a vector layer with the wrong projection,
the error prints to screen and then continues with the rest of the script
when I want to catch the error, log it and then exit. I have looked at the
error def here http://grass.osgeo.org/programming7/core_8py_source.html but
can't make sense of it!
Any help greatly appreciated.
Regards, Phil
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Handling-exceptions-with-Python-tp6860620p6860620.html
Sent from the Grass - Users mailing list archive at Nabble.com.
kungphil wrote:
I am fairly new to both Python and Grass...
I am trying to catch exceptions thrown up by GRASS using try/except but
can't seem to get it working!
For example
try:
grass.run_command('v.in.ogr', dsn=sLayer, output=sLayerName, quiet=True)
except:
...
run_command doesn't raise an exception if the command fails (returns a
non-zero exit status). Some time ago, there was an attempt to do this,
but it was so badly implemented that it was reverted.
If you want to know whether the command failed, you need to check the
exit status which run_command returns.
--
Glynn Clements <glynn@gclements.plus.com>
Hi,
2011/10/5 Glynn Clements <glynn@gclements.plus.com>:
run_command doesn't raise an exception if the command fails (returns a
non-zero exit status). Some time ago, there was an attempt to do this,
but it was so badly implemented that it was reverted.
I think that Python Scripting Library should contain mechanism for
raising exceptions. Please feel free to implement it in better way
than it was...
Martin
--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa