Unit 3 Programming Assignment
Unit 3 Programming Assignment
Question 2
try:
print("Result:", result)
except ZeroDivisionError as e:
print("Error Message:", e)
If the user enters a denominator of 0, the program will produce the following output:
Prevents Crashes: Error handling using try-except ensures that the program continues to run despite
encountering an error. Without it, the program would terminate abruptly when a division by zero
occurs.
User-Friendly: Error handling provides clear error messages that guide users and developers in
understanding the issue. It enhances user experience by preventing cryptic error messages or abrupt
program terminations.
Debugging: Error handling makes it easier for developers to identify and diagnose issues. It provides
valuable information about what went wrong, aiding in debugging and problem resolution.
Stability: Error handling contributes to program stability by gracefully handling unexpected situations. It
allows the program to recover from errors and continue executing other parts of the code.
Program Crashes: The program will crash when a division by zero occurs, leaving users with no
indication of what went wrong. This disrupts user tasks and may lead to data loss.
User Frustration: Users will encounter crashes and errors without explanations, leading to frustration
and a poor user experience.
Security Risks: Unhandled errors can be exploited by attackers to gain unauthorized access or disrupt
the program, posing security risks.
Debugging Challenges: Developers will have a harder time identifying and fixing issues since the program
terminates without providing information about the error.
In conclusion, error handling is essential for robust programming. It ensures that unexpected errors, like
division by zero, are handled gracefully, maintaining program stability, usability, and security. Not
handling such errors can lead to a host of problems, affecting both users and developers.