开发者

Print info about exception in python 2.5?

开发者 https://www.devze.com 2023-01-17 16:17 出处:网络
Python 2.5 won\'t let me use t开发者_如何学Pythonhis syntax: try: code_that_raises_exception() except Exception as e:

Python 2.5 won't let me use t开发者_如何学Pythonhis syntax:

try:
    code_that_raises_exception()
except Exception as e:
    print e
    raise

So how should I print information about an exception?

Thanks

EDIT: I'm writing a plugin for a program that includes kind of a pseudo python interpreter. It prints print statements but doesn't show exceptions at all.


the 'as' keyword is a python 3 (introduced in 2.6) addition, you need to use a comma:

try:
    code_that_raises_exception()
except Exception, e:
    print e
    raise


try:
  codethatraises()
except Exception, e:
  print e
  raise

not as easy to read as the latest and greatest syntax, but identical semantics.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号