1.

Why Can't I Globally Catch Exceptions From Mainloop?

Answer»

One of the often asked questions for wxPython has to do with why you can't use a global exception handler wrapped around the call to the app object's MainLoop method. To understand the answer to this QUESTION you NEED to keep in MIND that wxWidgets and the wxPython wrappers are C++ code and whenever an event handler or other callback is called you end up with another layer of C++ and Python code on the stack. I usually refer to this as the C++/Python sandwich. For example:

  1. You call MainLoop: this is a Python to C++ transition.
  2. The user CLICKS a button and your EVT_BUTTON handler is called, which TRANSITIONS back to Python
  3. The handler calls self.SetSize, now we are back in C++
  4. You have a EVT_SIZE handler that is called, which puts us back in Python
  5. The handler calls Layout(), back in C++
  6. The Layout causes some other panel to get resized, and it has it's own EVT_SIZE handler, now we're back in Python again.
  7. That EVT_SIZE handler calls Update to force an immediate repaint of the panel, putting us back in C++
  8. The handler for the EVT_PAINT is called, which puts control on the Python side once more.

One of the often asked questions for wxPython has to do with why you can't use a global exception handler wrapped around the call to the app object's MainLoop method. To understand the answer to this question you need to keep in mind that wxWidgets and the wxPython wrappers are C++ code and whenever an event handler or other callback is called you end up with another layer of C++ and Python code on the stack. I usually refer to this as the C++/Python sandwich. For example:



Discussion

No Comment Found