What is exception handling?

What is exception handling?

In software engineering, there's a catchphrase that gets used a lot. When writing code, there's emphasis on getting the code to "fail gracefully". What this means is that in the event that something unplanned for occurs the software would fail in a way that doesn't totally destroy the user's experience and leaves useful clues for the developer regarding how and why the software failed.

Exception handling is the term used to refer to the concept of getting software solutions to fail gracefully, the code we write is enclosed in a "try" block and just beneath the code we add a "catch" block then specify the exception we're trying to catch, we tend to include a "throw" within the "catch" block so as to specify the feedback that should be sent when the exception we're catching occurs. Sometimes we add a "finally" block so that no matter what happens, the software can execute something in the worst case scenario.

The thing with exception handling is that you can make fairly good guesses as to where the code will fail and create exceptions specifically for those scenarios. Exception handling is like tossing a ball in the air, you can make good guesses as to where and when the ball will fall then try to catch it.