Tuesday, 24 January 2017

TYPES OF ERROR IN PYTHON

Generally we get two types of errors in any programming language. They are-
 
1. Syntax errors – The errors which occurs because of invalid syntax are known
as syntax errors. Whenever we run the python program then internally we will 
check for the syntaxes. If any syntax is written wrongly then byte code will not be 
generated for the python program. Without generating the byte code program 
execution will not takes place. Python programmers or developers have to 
provide the solutions to the syntax errors.
 
2. Runtime errors – The errors which occur at the time of execution of the 
program are known as runtime errors. Generally we will get the runtime errors 
because of program logic, invalid input, memory related problems etc. With 
respect to runtime error corresponding class is available and we call those classes
 as a exception class. At the time of execution of the python program, if any 
runtime error is occurred then internally corresponding runtime error 
representation class object will be created. If the python program does not 
contain the code to handle that object then program will be terminated 
abnormally.
 
Abnormal Termination – The concept of terminating the program in the 
middle of its execution without executing last statement of the program is known
 as abnormal termination. Abnormal termination is the undesirable situation in 
any programming language.
 
Example –
print 'hi'
i=input('Enter num1 : ')
j=input('Enter num2 : ')
k=i/j
print k
print 'bye'
 
Output –
hi
Enter num1 : 10
Enter num2 : 0
Traceback (most recent call last):
  File "C:/Users/om/PycharmProjects/Pythonn/if3.py", line 4, in <module>
    k=i/j
ZeroDivisionError: integer division or modulo by zero

 

No comments:

Post a Comment