Results 1 to 9 of 9

Thread: Beginner: TRY and CATCH fonctions nothing catches

Threaded View

  1. #1

    Thread Starter
    New Member mrspock3333's Avatar
    Join Date
    Feb 2012
    Posts
    4

    Question Beginner: TRY and CATCH fonctions nothing catches

    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:
    vb.net Code:
    1. Try
    2.          monthlyInvestmenmt = convert.ToDecimal(txtMonthlyInvestment.Text)
    3.          YearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text)
    4.          years = convert.ToInt32(txtYears.Text)
    5. Catch ex As FormatException
    6.          messageBox.Show("A format exception has occurred. Plse check all _
    7.          entries.")
    8.  
    9. End Try
    -----my code below...

    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:
    1. Try
    2. Catch ex As Exception
    3.     If txtCurrValue.Text = "" Or txtRate.Text = "" Or txtPeriods.Text = ""
    4.          Then MessageBox.Show("Plse ensure all required field are complete")
    5.          Exit Sub
    6.     End If
    7.     Else
    8.          dblRate = TxtRate.Text
    9.     MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.StrackTrace, _
    10.     ex.GetType.ToString)
    11. 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.
    Last edited by Hack; Feb 9th, 2012 at 11:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width