Hi Vladimir, 2010/12/21 Vladimir Rutsky <[email protected]>: > What is the "policy of crashing" for application that use PySide?
exit(1) isn't really crashing. It's exiting because of an (unrecoverable?) error. > Last string (print "done") will not be reached because running > "QtGui.QWidget()" without initialized QApplication prints >> QWidget: Must construct a QApplication before a QPaintDevice > and exits python process with error code 1. > > May be such exceptional situations inside Qt should be treated as > exceptions in Python? I think this is the same behaviour as in C++ when Qt is used. The situation really is a programming error (you have to construct a QApplication, as the message tells you), and it could yield strange problems when somebody accidentally uses a catch-all except block in try..except. try..except should be used for situations where exceptions happen sometimes, but not always. In this case, the exception would be thrown all the time, so the code is never "valid", and therefore a try..except does not really make sense. I also believe (though do not know for sure - you'll have to check the source code) that this exit is in the Qt libraries, so PySide cannot really "convert" this exit into an exception without dirty hacks. Another situation where that happens is when you construct a QApplication without $DISPLAY set: $ export DISPLAY= $ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from PySide.QtGui import QApplication >>> app = QApplication([]) PySideApp: cannot connect to X server $ echo $? 1 In this case, I think it would be good to have an exception at the Python level, as this error is something that only happens when $DISPLAY is not set, so catching the exception and dealing with it (i.e. by printing a nice error message like "You do not have $DISPLAY set.") makes more sense. Should I turn this into a bug/feature request? HTH. Thomas _______________________________________________ PySide mailing list [email protected] http://lists.openbossa.org/listinfo/pyside
