vb.net拋出例外的錯誤

看板Programming作者時間18年前 (2006/12/09 08:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/4 (看更多)
假設我的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。 ○ 。。
文章代碼(AID): #15UVo_00 (Programming)
文章代碼(AID): #15UVo_00 (Programming)