One of my applications' OnInit() obtains hardware resources which are to be freed in OnExit() because otherwise there is a crash exitting the program. However, the OnInit() method is quite large because it initialises other things as well, and if any of these returns false the hardware resources should be freed explicitly too.
I would like to make a try/except block which catches any problem and frees the resource, but right know the method is written to just return False. Wouldn't it be OK to raise some exception? Does App.OnInit() require True/False to be returned because otherwise something bad might happen?
How do others deal with such long application initialisations?
···
--
Rastertech España S.A.
Grzegorz Adam Hankiewicz
/Jefe de Producto TeraVial/
C/ Perfumería 21. Nave I. Polígono industrial La Mina
28770 Colmenar Viejo. Madrid (España)
Tel. +34 918 467 390 (Ext.17) *·* Fax +34 918 457 889
ghankiewicz@rastertech.es *·* www.rastertech.es <http://www.rastertech.es/>
Grzegorz Adam Hankiewicz <ghankiewicz@rastertech.es> wrote:
One of my applications' OnInit() obtains hardware resources which are to
be freed in OnExit() because otherwise there is a crash exitting the
program. However, the OnInit() method is quite large because it
initialises other things as well, and if any of these returns false the
hardware resources should be freed explicitly too.
I would like to make a try/except block which catches any problem and
frees the resource, but right know the method is written to just return
False. Wouldn't it be OK to raise some exception? Does App.OnInit()
require True/False to be returned because otherwise something bad might
happen?
How do others deal with such long application initialisations?
One of my applications' OnInit() obtains hardware resources which are to be freed in OnExit() because otherwise there is a crash exitting the program. However, the OnInit() method is quite large because it initialises other things as well, and if any of these returns false the hardware resources should be freed explicitly too.
I would like to make a try/except block which catches any problem and frees the resource, but right know the method is written to just return False. Wouldn't it be OK to raise some exception? Does App.OnInit() require True/False to be returned because otherwise something bad might happen?
Yes the C++ code needs to have a True/False return value, however the wxPython wrapper has been made a little smarter for this case and it will raise a SystemExit exception if False is returned. It will also allow other exceptions to pass back through to the wx.App.__init__, so you should be able to catch them too if needed.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!