This document provides information about exception handling in Python. It begins with a disclaimer and introduction to the mentoring organization. It then defines that exceptions are events that modify program flow or control, such as errors, and can be caught using try/except blocks to handle errors gracefully or try/finally to perform cleanup. Code that may cause exceptions can be placed in a try block, followed by except blocks to handle specific exception types. The document provides an example syntax and contact information at the end.
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Exception handling
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
3. EXCEPTION HANDLING
SHEETHAL U
sheethu@gmail.com
www.facebook.com/sheethu
in.linkedin.com/in/sheethal
Ummanath
9447531524
4. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
5. EXCEPTION
Exceptions are events that can modify the
flow or control through a program.
They are automatically triggered on errors.
try/except : catch and recover from raised by
you or Python exceptions
try/finally: perform cleanup actions whether
exceptions occur or not
raise: trigger an exception manually in your
code
6. • An exception is an event, which occurs during
the execution of a program, that disrupts the
normal flow of the program's instructions.
• In general, when a Python script encounters a
situation that it can't cope with, it raises an
exception.
7. • If you have some suspicious code that may
raise an exception, you can defend your
program by placing the suspicious code in a
try: block.
• After the try: block, include an except:
statement, followed by a block of code which
handles the problem as elegantly as possible.
8. syntax
• try:
You do your operations here;
......................
except ExceptionI:
If there is ExceptionI, then execute this block.
except ExceptionII:
If there is ExceptionII, then execute this block.
......................
else:
If there is no exception then execute this block.