
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- What is difference between '.' , '?' and '*' in Python regular expression?
- what is the main difference between '=' and '==' operators in javascript?
- What is the difference between 'isset()' and '!empty()' in PHP?
- What is the difference between 'log' and 'symlog' in matplotlib?
- The difference between 'AND' and '&&' in MySQL?
- What is the difference between the 'COPY' and 'ADD' commands in a Dockerfile?
- Difference between 'include' and 'extend' in Ruby
- What is the difference between 'throw new Error' and 'throw someObject' in javascript?
- Write the main difference between '==' and '===' operators in javascript?
- Display the day in week using SimpleDateFormat('E') in Java
- SimpleDateFormat('E, dd MMM yyyy HH:mm:ss Z') in Java
- Difference between 'struct' and 'typedef struct' in C++?
- Difference between 'struct' and 'typedef struct' in C++ program?
- What is the relation between 'null' and '0' in JavaScript?
- What is the difference between throw e and throw new Exception(e) in catch block in java?
Advertisements