- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How do you handle an exception thrown by an except clause in Python?
We have a scenario in which code in except clause itself raises exception. In given code, we can handle the exception raised by except clause as follows.
import sys try: a = john except: try: 4/0 except: print sys.exc_info()
We get the following output
"C:/Users/TutorialsPoint1/~.py" (<type 'exceptions.ZeroDivisionError'>, ZeroDivisionError('integer division or modulo by zero',), <traceback object at 0x0000000002BD4B88>)
- Related Articles
- How to handle an exception in Python?
- How to catch an exception thrown by an async void method in C#?
- How to use the try-finally clause to handle exception in Python?
- How to handle an exception in JSP?
- How do you test that a Python function throws an exception?
- How can an exception be thrown manually by a programmer in java?
- How will you explain that an exception is an object in Python?
- How to raise an exception in one except block and catch it in a later except block in Python?
- How to handle an exception in JShell in Java 9?
- How do I manually throw/raise an exception in Python?
- How to handle Python exception in Threads?
- How to handle an exception using lambda expression in Java?\n
- How do you throw an Exception without breaking a for loop in java?
- How to loop the program after an exception is thrown in java?
- How do you make an array in Python?