From 25f702a031dd9ea78e47f03c8f9f9070be6106d8 Mon Sep 17 00:00:00 2001 From: Vamsi Andavarapu Date: Mon, 6 Jul 2026 20:58:38 +0530 Subject: [PATCH] Fix exception handling for deleted attribute Corrected exception type from NameError to AttributeError when accessing deleted attribute. --- Basics/Exercise/16_class_and_objects/16_class_and_objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Basics/Exercise/16_class_and_objects/16_class_and_objects.py b/Basics/Exercise/16_class_and_objects/16_class_and_objects.py index 4893cabc..a2d2985b 100644 --- a/Basics/Exercise/16_class_and_objects/16_class_and_objects.py +++ b/Basics/Exercise/16_class_and_objects/16_class_and_objects.py @@ -17,11 +17,11 @@ def display(self): # Deleting the object itself try: print(emp.id) -except NameError: +except AttributeError: #the exception is attribute error not name error print("emp.id is not defined") del emp try: emp.display() # it will gives error after deleting emp except NameError: - print("emp is not defined") \ No newline at end of file + print("emp is not defined")