2 Replies - 5603 Views - Last Post: 01 March 2011 - 06:39 AM Rate Topic: -----

#1 obliviate  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-February 11

how to use Try..Catch...Finally?

Posted 01 March 2011 - 06:28 AM

Hello...

i have this problem about the try,catch,finally statement... i don't know how to use it..
i have my converter program here and this should be type by a letter 'cause if you do it will go lag or hang...

i try VERIFY button to make sure if it's a letter or number but my teacher said it's not counted...

here's my code

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If ComboBox1.Text = "Pounds To Kilo" Then
            TextBox2.Text = TextBox1.Text * 0.45359237

        End If

        If ComboBox1.Text = "Ounce To Grams" Then
            TextBox2.Text = TextBox1.Text * 28.35
        End If

        If ComboBox1.Text = "Meter To Centimeter" Then
            TextBox2.Text = TextBox1.Text * 100
        End If
        If ComboBox1.Text = "Meter To Feet" Then
            TextBox2.Text = TextBox1.Text * 3.2808399
        End If

        Dim x As Integer
        Dim y As Integer

        x = TextBox1.Text
        y = TextBox2.Text

        Try

        Catch ex As Exception

        End Try

    End Sub
End Class




pls help me... i search about it but i cannot find a sample like that.. thanks for your help

Is This A Good Question/Topic? 0
  • +

Replies To: how to use Try..Catch...Finally?

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: how to use Try..Catch...Finally?

Posted 01 March 2011 - 06:38 AM

Putting your cursor on try and pressing F1 will give help and examples for its use.

Basically Put the code that could possibly produce an error between the Try and the Catch
Then in the Catch handle any errors.

Use finally to close any connections, or other objects that you need to dispose of.
Was This Post Helpful? 1
  • +
  • -

#3 Cyclopses  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 20-January 11

Re: how to use Try..Catch...Finally?

Posted 01 March 2011 - 06:39 AM

Won't do your homework, but if you want to know how Try works I'll give an example.

Try
'Converting Textbox.Text to Integers
Dim Value as Integer = CInt(Textbox1.text)

Catch ex As Exception
'This gets executed if it bugs out, thus it can't convert your textbox input to Integers
MsgBox("Do something crazy!")

'You won't have to worry about finally at the moment
End Try


Goodluck, and I hope I didn't spoil to much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1