 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 do you properly ignore Exceptions in Python?
This can be done by following codes
try: x,y =7,0 z = x/y except: pass
OR
try: x,y =7,0 z = x/y except Exception: pass
These codes bypass the exception in the try statement and ignore the except clause and don’t raise any exception.
The difference in the above codes is that the first one will also catch KeyboardInterrupt, SystemExit etc, which are derived directly from exceptions.BaseException, not exceptions.Exception.
It is known that the last thrown exception is remembered in Python, some of the objects involved in the exception-throwing statement are kept live until the next exception. We might want to do the following instead of just pass:
try: x,y =7,0 z = x/y except Exception: sys.exc_clear()
This clears the last thrown exception
Advertisements
 