© Mike Driscoll 2018
Mike DriscollwxPython Recipeshttps://doi.org/10.1007/978-1-4842-3237-8_20

20. Bonus Recipes

Mike Driscoll
(1)
Ankeny, New York, USA
 

Recipe 20-1. Catching Exceptions from Anywhere

Problem

If you use wxPython a lot, you will soon realize that some exceptions are difficult to catch. The reason it is so difficult is because wxPython is a wrapper around a C++ package called wxWidgets . Thus you have a mixture of C++ and Python in your application. What this means is that events bubble up from C++ to Python and back again. Where an exception occurs (the C++ side or the Python side) determines whether or not we will be able to catch it.

Solution

One solution that works in a lot of cases is using Python’s sys.excepthook . We’ll spend ...

Get wxPython Recipes: A Problem - Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.