- 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
How will you explain that an exception is an object in Python?
Yes in given code ‘err’ is an exception object.
In python everything is an object. And every object has attributes and methods. So exceptions much like lists, functions, tuples etc are also objects. So exceptions too have attributes like other objects. These attributes can be set and accessed as follows. There is the base class exception of which pretty much all other exceptions are subclasses. If e is an exception object, then e.args and e.message are its attributes.
In current Python implementation, exceptions are composed of three parts: the type, the value, and the traceback. The sys module, describes the current exception object in three variables, exc_type, exc_value, and exc_traceback.
The sys.exc_info() function returns a tuple of these three attributes, and the raise statement has a three-argument form accepting these three parts.
Given code gives the following output
(<type 'exceptions.ValueError'>, ValueError('could not convert string to int: Godzilla!',), <traceback object at 0x0000000002E33748>)
- Related Articles
- How do you test that a Python function throws an exception?
- How do you handle an exception thrown by an except clause in Python?
- What is an object in Python? Explain with examples
- How will you explain Python Operator Overloading?
- How to handle an exception in Python?
- How to raise an exception in Python?
- How will you explain Python namespaces in easy way?
- What is the correct way to pass an object with a custom exception in Python?
- Argument of an Exception in Python
- How to ignore an exception and proceed in Python?
- How to pass argument to an Exception in Python?
- How to insert an item to an array that is inside an object in MongoDB?
- Explain how Python is an interpreted language
- How will you explain Python for-loop to list comprehension?
- How to pass a variable to an exception in Python?
