CIS4930 PYTHON - ERROR HANDLING
AND MODULES EXAM 2025/2026
QUESTIONS AND ANSWERS 100% PASS
Syntax Error - ANS code that violates grammatical rules
When is Syntax error detected? - ANS parsing phase
Syntax Error Characteristics - ANS prevents program from running and gives error message
with location and type of error
Exceptions - ANS errors that occur during execution. something unexpected.
Exceptions Characteristics - ANS can cause the program to terminate. provide traceback
(type of error and where it occured)
ZeroDivisionError - ANS dividing by zero
NameError - ANS using variable that has not been defined
TypeError - ANS performing operations on incompatible data types
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED
, IndexError - ANS accessing an index that is out of range
ValueError - ANS An invalid value is used, which can occur if giving letters to int().
Error Handling - ANS writing code that anticipates errors and prevents them
Event Notification - ANS signaling that a specific event has occurred
Special-Case Handling - ANS dealing with unusual situations
Termination Actions - ANS executing cleanup code before exiting
Unusual Control Flows - ANS altering the normal flow of execution
try...except - ANS try:
# code that might raise exception
except ExceptionType as e:
# code that executes if error is raised
Handling ValueError - ANS while True:
try:
x = int(input("Enter a number: "))
break
except ValueError as e:
print("Error:", e, "Please try again with valid number")
print("You entered:", x)
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED
AND MODULES EXAM 2025/2026
QUESTIONS AND ANSWERS 100% PASS
Syntax Error - ANS code that violates grammatical rules
When is Syntax error detected? - ANS parsing phase
Syntax Error Characteristics - ANS prevents program from running and gives error message
with location and type of error
Exceptions - ANS errors that occur during execution. something unexpected.
Exceptions Characteristics - ANS can cause the program to terminate. provide traceback
(type of error and where it occured)
ZeroDivisionError - ANS dividing by zero
NameError - ANS using variable that has not been defined
TypeError - ANS performing operations on incompatible data types
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED
, IndexError - ANS accessing an index that is out of range
ValueError - ANS An invalid value is used, which can occur if giving letters to int().
Error Handling - ANS writing code that anticipates errors and prevents them
Event Notification - ANS signaling that a specific event has occurred
Special-Case Handling - ANS dealing with unusual situations
Termination Actions - ANS executing cleanup code before exiting
Unusual Control Flows - ANS altering the normal flow of execution
try...except - ANS try:
# code that might raise exception
except ExceptionType as e:
# code that executes if error is raised
Handling ValueError - ANS while True:
try:
x = int(input("Enter a number: "))
break
except ValueError as e:
print("Error:", e, "Please try again with valid number")
print("You entered:", x)
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED