Hi, I am trying to get TRY and CATCH fonctions to work, but nothing is catching, here is what I have done (note I am new to VB)...
In my textbook I have a sample:
-----my code below...vb.net Code:
Try monthlyInvestmenmt = convert.ToDecimal(txtMonthlyInvestment.Text) YearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text) years = convert.ToInt32(txtYears.Text) Catch ex As FormatException messageBox.Show("A format exception has occurred. Plse check all _ entries.") End Try
Now according to my instructions I must start the debugging to obtain the exception, but nothing will catch using my code, it just goes thru as it was meant to be...???
-------vb.net Code:
Try Catch ex As Exception If txtCurrValue.Text = "" Or txtRate.Text = "" Or txtPeriods.Text = "" Then MessageBox.Show("Plse ensure all required field are complete") Exit Sub End If Else dblRate = TxtRate.Text MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.StrackTrace, _ ex.GetType.ToString) End Try
When running the code it works fine, do I have to create an error for the code to catch it, and if nothing catches how do I know that the Try Catch functions worked?
I know it is basic, but that process is not clear to me, even after reading about it. Tks for your help.




Reply With Quote