Question Exception Handling (very confused and needs help)

Amstarr

New member
Joined
Apr 2, 2012
Messages
2
Programming Experience
Beginner
I am a beginner in vb.net and i need help with exception handling. My
program must include a Try, Catch, and Finally keywords and they must function correctly (i.e. if the user defines an impossible calculation, there must be an error message shown; if not, there must be some action to indicate there was no error even if it is simply showing the answer).

My program is a calculator that finds the volume of a cube if that is needed to help

Please any code shown how to do it or how it should look would be amazing this is what i have.

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim length As Integer
Dim Area As Integer
Dim Volumeanswer As Integer
Area = TextBox3.Text
length = TextBox4.Text
Volumeanswer = length * Area
MessageBox.Show(Volumeanswer)




End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim height As Integer
Dim width As Integer
Dim length As Integer
Dim AA As Integer
height = TextBox1.Text
width = TextBox2.Text
AA = height * width
MessageBox.Show(AA)
End Sub
End Class


This is what my application looks like

code.png

Thanks for anybody that try and helps!!!
 
I recommend that instead of TextBox control you use the NumericUpDown control, it is a numeric textbox control. This will eliminate invalid user input. If not you can use Integer.TryParse method to check and convert text to numbers.

Here you can read about Try-Catch and see examples of usage: Try...Catch...Finally Statement (Visual Basic)
 
Back
Top