0% found this document useful (0 votes)
24 views3 pages

Exception Handling

The document discusses exception handling in Python, explaining that errors can occur during program execution and are classified into syntax, run-time, and logical errors. It outlines the debugging process and the steps involved in exception handling, including the use of try...except blocks to manage errors. The document emphasizes that exception handling allows programs to recover from errors without termination.

Uploaded by

ordinal02bank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Exception Handling

The document discusses exception handling in Python, explaining that errors can occur during program execution and are classified into syntax, run-time, and logical errors. It outlines the debugging process and the steps involved in exception handling, including the use of try...except blocks to manage errors. The document emphasizes that exception handling allows programs to recover from errors without termination.

Uploaded by

ordinal02bank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

M.E.

S INDIAN SCHOOL, DOHA - QATAR


Notes

Section : Boys/ Girls


Class & Div. : XII( All divisions) Subject : Computer
Science Lesson / Topic: Exception Handling
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
INTRODUCTION:
 Apart from computer programs that we code, an exception or error or unusual condition can occur even
in our daily life.
 Sometimes an application can recover from an error and still provide normal, expected behaviour,
sometimes errors get reported to the user, sometimes they get logged to a file, etc. It depends on the
specific error and the application. The same is applicable in the field of computer programming also.

ERRORS IN PYTHON AND DEBUGGING

The process of finding errors in a program is termed as Debugging.


Errors in Python are classified mainly into three types:
(a) Syntax Error (b) Run-time Error (c) Logical Error
 A syntax error is an error in the syntax of a sequence of characters or tokens that is
intended to be written in a particular programming language. These types of errors are
generated when we violate the syntax or, in other words, the grammatical rules of a
programming language. syntax errors are:
1. Incorrect indentation
2. Misspelling a keyword
3. Leaving out a symbol such as colon (:), comma (,) or parentheses (()).

 A run-time error occurs after Python interpreter interprets the code you write and the
computer,begins to execute it. Run-time errors come in different types and some are hard to
find.
Some examples of Python run-time errors are:
1. Division by zero
2. Performing an operation on incompatible types
3. Using an identifier variable which has not been defined
4. Accessing a list element, dictionary value or object attribute which doesn’t exist
5. Trying to access a file that doesn’t exist

 Some examples of logical errors are:


1. Using the wrong variable name for calculations.
2. Using integer division or modulus operator in place of division operator
3. Giving wrong operator precedence.
What is Exception Handling?
Python also provides a complete mechanism for handling an error when it occurs. This mechanism is called
Exception Handling. An exception is an error that happens during the execution of a program. If an exception
is not caught, the program is terminated.

Error handling in Python involves the following steps:


• Firstly, the moment an error occurs the state of execution of the program is saved.
• Normal flow of the program is interrupted (stopped for a moment).
• A special function or piece of code known as exception handler is executed.
• Execution of the program is resumed with the previously saved data.
This process of error handling is called exception handling.
When we use try...except block in the script and an error is encountered, a try block code
execution is stopped and transferred down to the except block.
Syntax:
try:
You do your operations here
......................
except:
If there is an exception, then execute this block

You might also like