Exception Handling in Visual Basic .NET

We will first see the following code and run the program first. Here I am going to divide two numbers and show the results in a Label.

This the code for click event handler of the Button

Leave the TextBoxes blank and You click the Button.
What will be the error you can see?
So you will get error called InvalidCastException. Because you are casting blank space to Double data type

So I will add Try… Catch statement to handle it and show error message to user

Now you will get MessageBox with message Conversion from String “” to type Double is not valid

Using the Catch statement I catched the Exception and I showed custom error message to user without terminating the project