- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between 'except Exception as e' and 'except Exception, e' in Python?
The difference between using ',' and 'as' in except statements, is as follows:
Both ',' and 'as' are same functionality wise; but their use depends on the python versions as follows.
In Python 2.5 and earlier versions, use of the 'comma' is recommended since 'as' isn't supported.
In Python 2.6+ versions, both 'comma' and 'as' can be used. But from Python 3.x, 'as' is required to assign an exception to a variable.
As of Python 2.6 using 'as' allows us an elegant way to catch multiple exceptions in a single except block as shown below
except (Exception1, Exception2) as err
is any day better than
except (Exception1, Exception2), err
- Related Articles
- What is the difference between 'except Exception as e' and 'except Exception, e' in Python?
- What is the difference between throw e and throw new Exception(e) in catch block in java?
- How to raise an exception in one except block and catch it in a later except block in Python?
- How do you handle an exception thrown by an except clause in Python?
- Difference between system level exception and Application level exception.
- Difference between Interrupt and Exception
- Difference between Exception and Error in Java
- Difference Between Error and Exception in Java
- What is Exception in Python?
- Difference Between Checked and Unchecked Exception in Java
- try and except in Python
- What is exception handling in Python?
- What is the difference between E commerce and M commerce?
- What is the difference between E-commerce and traditional commerce?
- try and except in Python Program
- Difference between B2B e-Commerce and B2C e-Commerce

Advertisements