

- 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
How to rethrow Python exception with new type?
In Python 3.x, the code is subject to exception chaining and we get the output as follows
C:/Users/TutorialsPoint1/~.py Traceback (most recent call last): File "C:/Users/TutorialsPoint1/~.py", line 2, in <module> 1/0 ZeroDivisionError: division by zero
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:/Users/TutorialsPoint1/~.py", line 4, in <module> raise ValueError ( "Sweet n Sour grapes" ) from e ValueError: Sweet n Sour grapes
- Related Questions & Answers
- How to rethrow an exception in Java?
- How to implement a custom Python Exception with custom message?
- How to get Python exception text?
- How to rethrow InnerException without losing stack trace in C#?
- How to handle an exception in Python?
- How to catch KeyError Exception in Python?
- How to raise an exception in Python?
- How to catch IOError Exception in Python?
- How to catch ArithmeticError Exception in Python?
- How to catch OverflowError Exception in Python?
- How to catch IndexError Exception in Python?
- How to catch NameError Exception in Python?
- How to catch EOFError Exception in Python?
- How to catch SyntaxError Exception in Python?
- How to catch IndentationError Exception in python?
Advertisements