Welcome to the Implementing Exception Handling Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.
The following exam objective is covered in this lab:
- 1.4 Implement exception handling
It will take approximately 20 minutes to complete this lab.
Exercise 1 - Handling Exceptions
Exception handling involves adding provisions to handle exceptional/abnormal conditions in a program. Such conditions, if not handled, forces the program to crash. You need to include exception-handling elements in the program to change the normal flow of program execution. A robust program will take care of all possible exceptions.
You can use the try statement to define a code block that needs to be tested for any specific errors in the program. You can use the catch statement to define a code block that needs to be executed if an error is identified in the try code block. The try…catch block must be included in a pair. In other words, the try statement is not valid without a catch statement and vice-versa.
You can also include a finally statement after the try…catch block in the script. The syntax of the finally statement is as follows:
The finally block is executed regardless of the outcome of the try…catch block. It does not matter to the compiler if the exceptions are handled or not. The compiler will go ahead and always execute the finally statement block.
- Task 1 - You will download the Visual Studio Code workspace (Calculator) from the Intranet and open the HTML page named Calc.html in the Calculator workspace.
After completing this exercise, you will be able to:
See the full benefits of our immersive learning experience with interactive courses and guided career paths.