Traceback (most recent call last):
File "C:\Python24\pruebas\pruebaraise.py", line 38, in On_BtnCancelar
raise Exception("Cancelado por el usuario")
Exception: Cancelado por el usuario
···
=======================
Formulario NO Cancelado
The exception is raised but the 'try:' don't catch it.
Am i doing anything bad?
My system:
python 2.4.1
ws 2.6.1 unidoce
Windows XP
Im try to catch an exception raised in a dialog, but the try statement don't catch it
[...]
Traceback (most recent call last):
File "C:\Python24\pruebas\pruebaraise.py", line 38, in On_BtnCancelar
raise Exception("Cancelado por el usuario")
Exception: Cancelado por el usuario
Formulario NO Cancelado
The exception is raised but the 'try:' don't catch it.
Am i doing anything bad?
No. You are dealing with issues around what I call the "C++/Python sandwich". When you call MainLoop and then event handlers or other callbacks are invoked, and then you call other wx methods, which can then cause other callbacks, etc, etc, then you end up with a multi-layered C++/Python sandwich on the call stack. In the past when an exception happens in a Python layer there was not any safe way to propagate that exception across the C++ layer to the next Python layer up the stack, so instead when control returns to a C++ layer it checks if there was an exception and just calls PyErr_Print() if there was. So if you want to catch exceptions you need to do it within the same Python layer where it happens, before the event handler or callback returns to the C++ layer. It is possible that this can be changed now since wxWidgets has taken more care to be "exception safe" so that is something I am going to look into changing in the 2.7 series.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!