WxPython does not throw an exception when it should, instead of giving raw error messages

I am coding a menu for an application that I am writing in python using the wxPython libraries for the user interface, and I am trying to add icons to some menu items. Since I am trying to be honest in this, I am trying to limit the damage if one of the image files to which they refer does not exist, and the simplest method (in my opinion) is to use exceptions.

The problem is that when I refer to a file that does not exist, the exception is not thrown. Instead, I get a terrible message with the message:

Can't load image from <path>: Image does not exist.

This message is exactly the type I'm trying to stop, but even with the widest exception, the catching statement does not work.

This is an abridged version that seems to matter from what I wrote:

NewProject = wx.MenuItem(File, -1, "&New Project\tCtrl+N", "Create a new project")
try:
    # raises an error message but not an exception
    NewProject.SetBitmap(wx.Image( <path>  ), wx.BITMAP_TYPE_PNG).ConvertToBitmap())
except Exception:
    pass

So these are my questions: what am I doing wrong? Am I approaching this in the wrong direction, paying too much attention to exceptions when there are other ways around it (although this is not, as it seems to me, in my head)? Is this a bug in the wxPython library, since I'm sure it should be an exception, even if this is not the best way to do this?

ps The best way to search Google is to recommend that I convert all the images to python code using the module img2pythat comes with wxPython, but I would prefer to save the images in image format for what I do.

+3
1

. Robin Dunn : , :

dummy_log=wx.LogNull()

dummy_log , .

+3

All Articles