Exception_Handling_in_. Python_PPT.pptx

priyanshuraj142007 0 views 9 slides Oct 08, 2025
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

Exception handling in python


Slide Content

Exception Handling in Python Student Name: Navya Kumari Roll No: 2024-E-48

Introduction - Error = problem in program - Exception = error during execution - Exception handling makes program safe - Prevents sudden crash

Theory (Basics) - try → risky code - except → handles error - else → if no error - finally → always runs - raise → generate error

Theory (Clauses & Classes) - try–except–else clause - try–finally clause - Multiple except blocks - Built-in Exceptions: ZeroDivisionError, ValueError, TypeError

Working Code (Example 1) try: x = int(input('Enter number: ')) y = int(input('Enter another: ')) print(x / y) except ZeroDivisionError: print('Cannot divide by zero') finally: print('Done')

Working Code (Example 2 - Raising) age = -3 if age < 0: raise ValueError('Age cannot be negative')

Questions One Word: - Keyword to raise exception → raise - Keyword always executed → finally Match: 1. try → test 2. except → handle 3. else → if no error 4. finally → always run MCQs: 1. Divide by zero error → ZeroDivisionError 2. Optional block → else Fill in the blanks: 1. Block to catch errors → except 2. Keyword to raise error → raise

Conclusion - Exception handling avoids program crash - Provides safe error recovery - Makes applications more reliable

Thank You Presented by: Navya Kumari Roll No: 2024-E-48
Tags