雙語例句
- to err is human, and nobody likes a perfect person. n是人都會犯錯,而且誰也不喜歡完人。nIf you make a threat be sure to carry it out if he errs again. n如果你作出威脅,在他再犯錯時,一定要說到做到。I thought it was better to err on the side of caution. n我認為甯可過于謹慎也不要冒風險。n
說明
Err對象的屬性是由錯誤的生成者(Visual Basic、對象或程序員)設置的。當發生運行時錯誤時,Err對象的屬性由唯一地标識錯誤的信息以及可用于處理錯誤的信息填充。若要在代碼中生成運行時錯誤,使用Raise方法。在錯誤處理例程中的Exit Sub、Exit Function、Exit Property或Resume Next語句執行之後,Err對象的屬性重置為零或零長度字符串(“”)。在錯誤處理例程以外,使用任何形式的Resume語句都不會重置Err對象的屬性。但可使用Clear方法顯式地重置Err。
使用Raise方法而不是Error語句來給系統錯誤和類模塊生成運行時錯誤。是否要在其他代碼中使用Raise方法決定于您需要返回的信息的多少。
Err對象是一個全局作用域的内部對象。因此,不需要在代碼中創建其實例。
示例本示例在構建錯誤信息對話框時使用了Err對象的屬性。有兩個方法clear,raise,5個屬性:description,helpcontext,helpfile,number,source請注意,如果首先使用Clear方法,則使用Raise方法生成Visual Basic錯誤時,Visual Basic的默認值将成為Err對象的屬性。
Dim Msg As String
' If an error occurs, construct an error message.
On Error Resume Next ' Defer error handling.
Err.ClearErr.Raise(6) ' Generate an "Overflow" error.
' Check for error, then show message.
If Err.Number <> 0 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & ControlChars.CrLf & Err.Description
MsgBox(Msg, MsgBoxStyle.Information, "Error")
End If
命名空間:Microsoft.VisualBasic
程序集:Microsoft Visual Basic .NET
運行庫(位于 Microsoft.VisualBasic.dll 中)