try
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供靖州網(wǎng)站建設(shè)、靖州做網(wǎng)站、靖州網(wǎng)站設(shè)計、靖州網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、靖州企業(yè)網(wǎng)站模板建站服務,10年靖州做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務。
‘可能出錯的代碼
catch ex……
出錯后運行這里的代碼,可以通過ex返回錯誤信息。
end try
try是捕獲異常的關(guān)鍵字
try
{
正常執(zhí)行代碼段;
}
catch(Exception err)
{
錯誤代碼段;
//例如
MessageBox.Show(err.Message);
//可以顯示你出的是什么錯誤
}
Public Class Form1
Public Class Circl
Dim _radius As Single '#1
Public Function Area() As Single
Return _radius ^ 2 * 3.14 '#2
End Function
Public Property Radius() '#3
Get
Return Area() '#4
End Get
Set(ByVal value)
If value = 0 Then
_radius = value '#5
Else
_radius = 0
MsgBox("半徑不能為負數(shù)") '#6
End If
End Set
End Property
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim c As New Circl '#7
c.Radius = Convert.ToSingle(txbradius.Text) '#8
txbarea.Text = c.Area '#9
Catch ex As Exception
MsgBox(ex.Message) '#10
End Try
End Sub