[Qgis-developer] Exception thrown from python call crashes qgis

Martin Dobias wonder.sk at gmail.com
Sat Jan 31 16:31:01 EST 2009


On Sat, Jan 31, 2009 at 6:52 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> My autosave plugin uses QgsProject.instance().write() to save the
> project to a backup location, but if there's a problem writing to the
> file then an Exception is thrown by the C++ and it crashes Qgis:
>
> QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed:
> Permission denied
> terminate called after throwing an instance of 'QgsIOException'
>  what():  Unable to save to file /home/rowlings/Work/Qgis/SaveTest/wooo.qgs
> Aborted

I've found out that by default SIP doesn't try to catch C++
exceptions. One has to pass -e option to SIP executable when
generating code (for qgis it's in file python/configure.py.in). From a
simple test it's able to catch the exception. I've tried also to wrap
QgsIOException using %Exception annotation (see SIP reference) but
couldn't force SIP in few quick attempts to identify the exception.
But at least it detects an unknown exception and doesn't abort.


>  To replicate, load a project then set the project's file and folder
> to read-only or no permissions at all. Saving the project from the
> File menu option brings up an error dialog, but doing
> QgsProject.instance().write() crashes it out with the above dump.

I have a simple test case:
from qgis.core import *
p = QgsProject.instance()
p.setFileName("/root/tst.qgs")
p.write()


>  Relevant code is in this method:
>
> http://doc.qgis.org/qgsproject_8cpp-source.html#l00920
>
>  where it throws a QgsIOException.

In my opinion, rather than trying to catch the exception we should
remove usage of exceptions from QGIS code completely (like in Qt).
There are just very few occurences so it shouldn't be that hard.

Martin


More information about the Qgis-developer mailing list