If you are facing any issue in playing video please use Firefox browser.
Exception Handling in Python 1
In this section we will see that,
What is exception ?
What is error ?
Which are the different types of exception ?
Which are the terms to handle the exceptions in Python ?
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instruction.
Errors detected during execution are called exceptions.
In Python there are two distinguishable kinds of errors : syntax errors and exceptions.
Syntax errors, also known as parsing errors.
for i in range(1,10)
Here missing":" after for is syntax error.
10*(1/0) : ZeroDivisionError : division by zero.
4+spam*3 : NameError : name 'spam' is not defined.
'2'+2 : TypeError : Can't convert 'int' object to str implicitly.
Exception handling in Python
Eg. n=int(input("Please enter a number:"))
Please enter a number:23.50
Exception occurs like ValueError: invalid literal for int() with base 10: '23.5'
With all the the keywords mentioned below we can handle the exceptions of python -
n=input("Please enter an integer:")
print("no valid integer! please try again")
print("great!! you successful entered an integer!")
A try statement may have more than one except clause.
But at most one except clause will be executed.
Have a friend to whom you would want to share this course?