5 Comments

  • I too thought it was pretty cool when I first saw it, but frankly I've never found a use for it in real code, so I'm not sure how useful it actually is.



    There's no equivalent in C#.



    You don't get a DivideByZeroException because you're using the floating point division operator (/) and not the integer division one (\). Only integer division by zero throws, floating point generates NAN or infinity or something like that.

  • 0/0 is NaN (Not a Number). If x>0, then x/0 is Infinity ; if x<0, then x/0 is -Infinity. It's defined in the rules of IEEE (some number which I definitely don't know off the top of my head) floating point numbers somewhere.



    Incidentally, you can definitely get the same behavior in C#, as per...



    private void button1_Click(object sender, System.EventArgs e)

    {

    int x = int.Parse(textBox1.Text);

    try

    {

    MessageBox.Show(((double) x/ (double) x).ToString());

    }

    catch(Exception ex)

    {

    this.Text = ex.Message;

    }

    }

  • I think the bigger picture is you shouldn't be using exception handling to catch divide by zero errors. Logic! Logic! Logic! :)


  • How to show the exceptio via messegebox here: HELP



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

    ' for Add button of clients bill form

    Try

    i1 = NumericUpDown2.Value

    tot = tot + i1

    TextBox13.Text = tot

    C1 = DataSet41.Clientbill1.NewClientbill1Row()

    C1("Branch_ss") = TextBox1.Text

    C1("Name_s") = TextBox2.Text

    C1("City_s") = TextBox3.Text

    C1("Ref_s") = TextBox4.Text

    C1("Billno_s") = TextBox5.Text

    C1("Billdate_ss") = TextBox6.Text

    C1("Estno_s") = TextBox7.Text

    C1("Estdate_s") = TextBox8.Text

    C1("Nameofpub_s") = TextBox9.Text

    C1("Size_s") = TextBox10.Text

    C1("Insertiondate_s") = TextBox11.Text

    C1("Totalspace_s") = TextBox12.Text

    C1("Rate_s") = NumericUpDown1.Value

    C1("Grossamount_s") = NumericUpDown2.Value

    C1("Total_s") = TextBox13.Text

    DataSet41.Clientbill1.AddClientbill1Row(C1)

    'OleDbDataAdapter1.ContinueUpdateOnError = True

    ' If DataSet41.HasChanges = True Then

    ' MsgBox("hi")

    'OleDbUpdateCommand1.ExecuteNonQuery()

    OleDbDataAdapter1.Update(DataSet41)

    Catch ex As Exception

    'MessageBox()

    End Try

    'End If



    End Sub

  • just use ex.ToString() or ex.Message in your messagebox.

Comments have been disabled for this content.