vb.net拋出例外的錯誤
假設我的textbox2.text=-5
應該會拋出例外
可是
程式為何還會跑else部分呢
謝謝
附上原始程式碼
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim car1 As New excar
Dim a, b As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
car1.setCar(a, b)
car1.show()
End Sub
End Class
Public Class CarException
Inherits ApplicationException
Public Sub New()
MyBase.New("錯誤")
End Sub
End Class
Class excar
Private num As Integer
Private gas As Double
Sub New()
num = 0
gas = 0.0
MsgBox("已生產了汽車")
End Sub
Public Function setCar(ByVal n As Integer, ByVal g As Double)
If (g < 0) Then
Throw New CarException
Else
num = n
gas = g
MsgBox("已使車號為" & num & ",使汽油量為" & gas)
End If
End Function
Public Function show()
MsgBox("車號是" & num)
MsgBox("汽油量是" & gas)
End Function
End Class
--
o ╔╦╦╦╦╦╦╦╗o。心靈交流的橋樑 資訊傳遞的園地 建築夢想的別境 o○。
。╠銘傳╬築夢別境╣ 。 ≡telnet://bbs.mcu.edu.tw≡ o
○╚╩╩╩╩╩╩╩╝○o From:218-169-110-200.dynamic.hi。 ○ 。。
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章