Why is error handling important?
Error handling refers to writing code which anticipates errors that are likely to happen and then responds to them. For successful running, a progrsm needs the right set of inputs and the ability to do its work, and it must appropriately return its output. Errors can occur during any of these stages. Well-written programs have error-handling code that anticipates and deals with errors that might happen at each stage.
How do you handle errors in a program?
Error handling can just be code that checks specific conditions and values before continuing. If the conditions are values are appropriate, execution proceeds along one path, otherwise, it follows a different path.
What is an exception?
An exception is a special error condition that responds to a certain type of error. One common approach is to check whether input is in the right format. When a user inputs their age, a positive number is expected. You can add code to check for a positive number before continuing and then raise an exception if anything else is inserted.