Error and Exception Handling
Error and Exception Handling
Python Programming
Using Problem Solving Approach
Reema Thareja
other hand, are caused by events that are beyond the control of the program.
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.
Syntax and Logic Errors
Syntax errors occurs when we violate the rules of Python and they are the most common kind of error that we
get while learning a new language. For example, consider the lines of code given below.
>>> i=0
>>> if i == 0 print(i)
SyntaxError: invalid syntax
Logic error specifies all those type of errors in which the program executes but gives incorrect results. Logical
error may occur due to wrong algorithm or logic to solve a particular program. In some cases, logic errors
may lead to divide by zero or accessing an item in a list where the index of the item is outside the bounds of
the list. In this case, the logic error leads to a run-time error that causes the program to terminate abruptly.
These types of run-time errors are known as exceptions. 4
10
11
Example:
12
Example:
13
Example:
14
15
17
18
20