2

I created a static HTML window in my wxPython application with:

wx.html.HtmlWindow.LoadPage(url)

It works well, and displays the HTML window in the application.

I am looking for a way to do exception handling for it, in case the website or Internet access is down, and it is unable to find the webpage link.

I tried two methods:

try:
    wx.html.HtmlWindow.LoadPage(url)
except:
    ...

And:

if wx.html.HtmlWindow.LoadPage(url):
    ...
else:
    ...

But for either test, if I use a URL that is not available, I will get a Python error that pops up with "Unable to open requested HTML document...", and the exception handler does not work.

I'd like to be able to handle exceptions and allow the program to continue running.

How can I perform error/exception handling for wx.html.HtmlWindow.LoadPage(...)?

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • I tried to load a bad URL in the wxPython demo and it just outputs a message that it was unable to open the requested HTML document. You'll have to create a small runnable example along with a test URL. Also, which version of wxPython are you using and on what OS? – Mike Driscoll Apr 10 '13 at 14:22
  • Hi Mike, I am using Windows 7, Python27, and wxpython version 2.8.12.1. I ended up partially solving this for now by checking the url first then creating the html window. I'd prefer a error handler for the html window, if anyone knows of one. Here is the code now: – user2263288 Apr 16 '13 at 16:37
  • WebPageLink = 'https://maps.google.ca/maps?hl=en&tab=wl' try: urllib2.urlopen(WebPageLink) except URLError, e: TextMessage ='Unable to display your site.' + '\n'+ str(e) TopLabel = 'Error' wx.MessageBox(TextMessage, TopLabel , wx.OK | wx.ICON_ERROR) self.m_htmlWin1.SetBackgroundColour( wx.Colour( 128, 128, 255 ) ) return() self.m_htmlWin1.LoadPage(WebPageLink) – user2263288 Apr 16 '13 at 16:40

0 Answers0