© 2004-19

Error Handling

This is part of a wider topic generally referred to as Robust programming.
This is a style of programming that focuses on handling unexpected termination and unexpected actions.
It requires code to handle these terminations and actions gracefully by displaying accurate and unambiguous error messages.
These error messages allow the user more confidence in the program and allow them to modify their action (eg the data being input) so that it is in the format or range the program is expecting.

There is another aspect to robust programming in that it should also protect the system form malicious attack.
Hackers are always looking for ways to exploit weaknesses in computer software and being very strict about what data is allowed to be input is part of creating a robust system.


Check out some of the code snippets to see how it works in practice

Method Description
Basic Try/Except Using Try/Except to validate a number
Try/Except with Assert Using Try/Except to validate a number in a range. Shows how to handle multiple exceptions