在VB.Net中,
我有函数x()&函数y()。 x()调用y()。
我如何构建y()代码?
答案 0 :(得分:2)
您只需在Y中使用Try Catch Block构建代码,如下所示:
Public Sub X()
Try
### Do some crucial operation here
Dim obj = Y() 'call Y
If Not obj Is Nothing Then
'do some operation on obj if the call to Y succeeded
End If
### Do more crucial operation here - this runs even if Y throws an exception
Catch ex As Exception
'x failed for some reason - log the ex.StackTrace and ex.Message
End Try
End Sub
Public Function Y() As Object
Try
Dim obj As New Object
'do y here
Return obj
Catch ex As Exception
'ignore any error that occurs calling y
Return Nothing
End Try
End Sub