试图在计算器中捕捉除以零的异常并且它不起作用,不确定我哪里出错了?
Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click
If lblOperator.Text = "+" Then
txtAnswer.Text = Val(txtNumberOne.Text) + Val(txtNumberTwo.Text)
ElseIf lblOperator.Text = "-" Then
txtAnswer.Text = Val(txtNumberOne.Text) - Val(txtNumberTwo.Text)
ElseIf lblOperator.Text = "x" Then
txtAnswer.Text = Val(txtNumberOne.Text) * Val(txtNumberTwo.Text)
ElseIf lblOperator.Text = "/" Then
Try
txtAnswer.Text = Val(txtNumberOne.Text) / Val(txtNumberTwo.Text)
Catch ex As Exception When Val(txtNumberTwo.Text = 0)
MessageBox.Show("You cannot divdide by zero")
End Try
End If
End Sub