Update 2025-2026
Syntax Error - Answers code that violates grammatical rules
When is Syntax error detected? - Answers parsing phase
Syntax Error Characteristics - Answers prevents program from running and gives error message
with location and type of error
Exceptions - Answers errors that occur during execution. something unexpected.
Exceptions Characteristics - Answers can cause the program to terminate. provide traceback
(type of error and where it occured)
ZeroDivisionError - Answers dividing by zero
NameError - Answers using variable that has not been defined
TypeError - Answers performing operations on incompatible data types
IndexError - Answers accessing an index that is out of range
ValueError - Answers An invalid value is used, which can occur if giving letters to int().
Error Handling - Answers writing code that anticipates errors and prevents them
Event Notification - Answers signaling that a specific event has occurred
Special-Case Handling - Answers dealing with unusual situations
Termination Actions - Answers executing cleanup code before exiting
Unusual Control Flows - Answers altering the normal flow of execution
try...except - Answers try:
# code that might raise exception
except ExceptionType as e:
# code that executes if error is raised
Handling ValueError - Answers 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)
except: - Answers catches all exception types
(use with caution)
except name:
ex- except ValueError: - Answers catches specific exception
except name as value:
ex- except ValueError as e: - Answers catches specific exception and assigns it to variable e
except (name1, name2):
ex- except (NameError, ValueError): - Answers catches listed exceptions
except (name1, name2) as value:
ex- except (NameError, ValueError) as value: - Answers catches any of listed exceptions and
assigns the exception instance to the variable value
else and finally blocks - Answers else executed if exception does not
finally always executes
Raising exceptions - Answers signals errors
create customs exceptions
def deliverPizza():
if not addressLocatable():
raise RuntimeError("Address not locatable")
raise SystemExit or sys.exit() - Answers terminate program
except KeyboardInterupt as k: - Answers Ctrl+C entered