I'm coding the menu for an application I'm writing in python, using wxPython libraries for the user interface, and I'm attempting to add icons to some of the menu items. Because I'm trying to be conscientious about it, I'm trying to limit the damage done if one of the image files referenced doesn't exist, and the most simple method (in my mind) is to use exceptions.
The trouble is, when I link to a file that doesn't exist, an exception isn't thrown. Instead I get a horrific message box stating:
Can't load image from <path>: Image does not exist.
This message is exactly the type of thing I'm trying to stop, but even with the broadest exception catching statement nothing works.
This is a cut down version, taking what seems to be relevant, from what I've written:
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, putting too much emphasis on exceptions, when there are other ways around it (though non that seem in my head to be as simple)? Is this a bug in the wxPython library, since I'm pretty sure it should be throwing an exception even if it's not the best way around it?
p.s. The best a Google search could do was recommend I converted all the images to python code using the img2py
module that comes with wxPython, but I would prefer to keep the images in image format for what I'm doing.