Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Exception Handling in Python 2

 

In this lecture we will see that,

How to perform exception handling in Python ?

How to raise the exception ?

 

print('hey')

try:

c='2'+4

except Exception:

print('You cannot enter string')

print('Good Bye')

O/P :

hey

You cannot enter string

Good Bye

 

Similarly we can use all the error blocks in one code and it will execute one error block according to the action.

 

Try .....finally clause

 

Finally clauses are called clean-up or termination classes, because they must be executed under all circumstances, ie. a "finally" clause is always executed regardless if an exception occurred in a try block or not.

 

raise

 

To explicitly raise exception at that time we can use raise.

 

raise Exception()

raise Exception("Something happened in my program")

 

Example :

c=8

if c>5:

raise Exception ("c has to be less than 5")

print("Finish")

O/P :

Exception : c has to be less than 5

Finish

 

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere