Mark As Completed Discussion

Try/Catch Statements

When an error occurs during the execution of a program, the compiler of the programming language will stop execution and generate an error message. However, if we want to control what happens when an error occurs, we can use try/catch statements. They are triggered when an error occurs during the execution of the program. The try block allows to check for any errors and its body executes statements (if any) in case errors were not occured. The catch block allows the programmer to handle the error by telling the program what to do if the try block catches any errors.