- 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 to handle python exception inside if statement?
The code can be written as follows to catch the exception
a, b=5, 0 try: if b != 0: print a/b else: a/b raise ZeroDivisionError except Exception as e: print e
We get the following output
C:/Users/TutorialsPoint1/~.py integer division or modulo by zero
- Related Articles
- How to handle exception inside a Python for loop?
- How to handle an exception in Python?
- How to handle Python exception in Threads?
- How to handle IllegalArgumentException inside an if using Java
- How to handle a python exception within a loop?
- How to handle an exception in JSP?
- How to use the try-finally clause to handle exception in Python?
- How to handle the Runtime Exception in Java?
- How to handle the exception using UncaughtExceptionHandler in Java?
- How to get the Current URL inside the @if Statement in Laravel?
- How to handle Java Array Index Out of Bounds Exception?
- How to handle an exception using lambda expression in Java?
- How to handle an exception in JShell in Java 9?
- What is the best way to handle list empty exception in Python?
- How do you handle an exception thrown by an except clause in Python?

Advertisements