Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
EXCEPTION HANDLING SHEETHAL U firstname.lastname@example.org www.facebook.com/sheethu in.linkedin.com/in/sheethal Ummanath 9447531524
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
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
• An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the programs instructions.• In general, when a Python script encounters a situation that it cant cope with, it raises an exception.
• 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.
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.