Beginners question about exceptions
#1
The code:

Code:
try:
    hkey = _winreg.LoadKey(_winreg.HKEY_LOCAL_MACHINE, _ReportMappingTable, filename)
    dialog.ok("MCERemote", "Done!", "Please restart Windows to activate the changes.")
except WindowsError as e:
    dialog.ok("MCERemote", "Error loading:", filename, e.args)

gives me a sytax error at "except WindowsError as e:". My limited understand of Python suggests this code should be legal. If it isn't, how do I get the text message associated with the exception?

Thanks,

JR
Reply
#2
are you sure that is the type of the exception? cause the syntax is ok.
Reply
#3
spiff Wrote:are you sure that is the type of the exception? cause the syntax is ok.

Pretty sure, but anyway it's a syntax error not a runtime error so it wouldn't matter if I got the exception name wrong. The error in xbmc.log is:

Code:
INFO: -->Python script returned the following error<--
ERROR: Error Type: exceptions.SyntaxError
ERROR: Error Contents: ('invalid syntax', ('C:\\Documents and Settings\\renniej\\Application Data\\XBMC\\addons\\plugin.script.mceremote\\default.py', 113, 30, '        except WindowsError as e:\n'))
ERROR:   File "C:\Documents and Settings\renniej\Application Data\XBMC\addons\plugin.script.mceremote\default.py", line 113
                  except WindowsError as e:
                                                                     ^
                SyntaxError: invalid syntax
INFO: -->End of Python script error report<--

I tried:

Code:
except Exception as e:

and got:

Code:
ERROR:   File "C:\Documents and Settings\renniej\Application Data\XBMC\addons\plugin.script.mceremote\default.py", line 113
                 except Exception as e:
                                   ^
             SyntaxError: invalid syntax

JR
Reply
#4
okay, seems this is different in python 2.4.

Code:
try:
   stuff
except WindowsError, e:
  print e

http://rgruet.free.fr/PQR24/PQR2.4.html#exceptionSts
Reply
#5
Thanks, that works :-)

JR
Reply

Logout Mark Read Team Forum Stats Members Help
Beginners question about exceptions0