Home » Python

How to ignore Exceptions in Python?

Python | Ignoring Exceptions: Here, we are going to learn how to ignore exceptions and proceed in Python?
Submitted by Sapna Deraje Radhakrishna, on February 01, 2020

What is an Exception?

An exception is an event, which occurs during the execution of a program that interrupts the normal execution of the application. Generally, any application when encountered with a situation that it can not handle (or such implementation is not implemented), the application throws ( or raises in Python) an exception.

The exception that is a runtime, blows the application. However, it is a good practice to always handle the exception immediately than let the application propagate which might terminate the application with a bulk error message.

Handling Exception in Python

The try-except syntax is as follows:

try:
	statements
except Exception1:
	<handle exception 1>
except Exception2:
	<handle exception2>
else:
	print("Nothing went wrong")
finally:
	print("will'be executed regardless if the try block raises an error or not")

Ignoring the exceptions

When you want to ignore an exception, use the key word "pass". Below are few examples,

    try:
	    <do something>
    except:
	    pass
    try:
	    <do something>
    except Exception:
	    pass 






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.