Home > Software design >  Which python version supports syntax like "except Exception, e"?
Which python version supports syntax like "except Exception, e"?

Time:04-14

I am working with a git repo that is showing syntax error for "except Exception, e:"

I am using Python 2.7.

which python version supports syntax like "except Exception, e"?

CodePudding user response:

except Exception, e

In Python 3.x the syntax is:

except Exception as e:
    ...

As you can see here the same syntax was used in version 2.7.

CodePudding user response:

except Exception,e:

same stynax with:

except Exception as e:

Its not related with python version, You may look PEP document.

PEP 3110: "Catching Exceptions in Python 3000"

CodePudding user response:

What you are looking for is:

                try:
                    do_sth()
                except Exception as ex:
                    traceback.print_exc()
                    print(ex.message)
                    print(ex.args)
  • Related