ErrObject.Number 속성

정의

오류를 지정하는 숫자 값을 반환하거나 설정합니다. 읽기/쓰기입니다.

public:
 property int Number { int get(); void set(int value); };
public int Number { get; set; }
member this.Number : int with get, set
Public Property Number As Integer

속성 값

오류를 지정하는 숫자 값을 반환하거나 설정합니다. 읽기/쓰기입니다.

예외

Number가 65535보다 큽니다.

예제

이 예제에는 일반적인 사용 방법을 보여 줍니다.는 Number 오류 처리 루틴에서 속성입니다.

    ' Typical use of Number property.
Sub test()
  On Error GoTo out

  Dim x, y As Integer
  x = 1 / y   ' Create division by zero error.
  Exit Sub
out:
  MsgBox(Err.Number)
  MsgBox(Err.Description)
  ' Check for division by zero error.
  If Err.Number = 11 Then
      y = y + 1
  End If
  Resume Next
End Sub

이 예제에서는 합니다 Err 개체의 Raise Visual Basic로 작성 된 함수에 원래 오류를 생성 하는 방법입니다. 호출 하는 함수는 오류를 catch 하 고 사용자에 게 보고할 수 있습니다. 프로시저 CallingProcedure 에서 파생 시킬 수 있는 정보를 대조를 Err 에서 파생 시킬 수 있는 정보를 사용 하 여 개체를 Exception 개체입니다.

Module Module1

    Const WidthErrorNumber As Integer = 1000
    Const WidthHelpOffset As Object = 100

    Sub Main()
        CallingProcedure()
    End Sub

    Sub TestWidth(ByVal width As Integer)
        If width > 1000 Then
            ' Replace HelpFile.hlp with the full path to an appropriate
            ' help file for the error. Notice that you add the error 
            ' number you want to use to the vbObjectError constant. 
            ' This assures that it will not conflict with a Visual
            ' Basic error.
            Err.Raise(vbObjectError + WidthErrorNumber, "ConsoleApplication1.Module1.TestWidth", 
                "Width must be less than 1000.", "HelpFile.hlp", WidthHelpOffset)
        End If
    End Sub

    Sub CallingProcedure()
        Try
            ' The error is raised in TestWidth.
            TestWidth(2000)
        Catch ex As Exception
            ' The Err object can access a number of pieces of
            ' information about the error.
            Console.WriteLine("Information available from Err object:")
            Console.WriteLine(Err.Number)
            Console.WriteLine(Err.Description)
            Console.WriteLine(Err.Source)
            Console.WriteLine(Err.HelpFile)
            Console.WriteLine(Err.HelpContext)
            Console.WriteLine(Err.GetException)

            Console.WriteLine(vbCrLf & "Information available from Exception object:")
            Console.WriteLine(ex.Message)
            Console.WriteLine(ex.ToString)

            Err.Clear()
        End Try
    End Sub
End Module

' The example produces the following output:
' Information available from Err object:
' -2147220504
' Width must be less than 1000.
' ConsoleApplication1.Module1.TestWidth
' HelpFile.hlp
' 100
' System.Exception: Width must be less than 1000.
'    at Microsoft.VisualBasic.ErrObject.Raise(Int32 Number, Object Source, Object
' Description, Object HelpFile, Object HelpContext)
'    at ConsoleApplication1.Module1.TestWidth(Int32 width) in C:\Users\example\App
' Data\Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 17
'    at ConsoleApplication1.Module1.CallingProcedure() in C:\Users\example\AppData
' \Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 25
'
' Information available from Exception object:
' Width must be less than 1000.
' System.Exception: Width must be less than 1000.
'    at Microsoft.VisualBasic.ErrObject.Raise(Int32 Number, Object Source, Object
' Description, Object HelpFile, Object HelpContext)
'    at ConsoleApplication1.Module1.TestWidth(Int32 width) in C:\Users\example\App
' Data\Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 17
'    at ConsoleApplication1.Module1.CallingProcedure() in C:\Users\example\AppData
' \Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 25

설명

모든 합니다 Raise 제외한 인수 Number 는 선택 사항입니다. 속성 설정 및 선택적 인수를 생략 하면는 Err 지워지지 않은 값을 포함 하는 개체, 해당 값이 오류에 대 한 값으로 사용 합니다.

때문에 Err 개체는 사용 하 여 오류를 생성 하는 경우 보다 더 많은 정보를 제공 합니다 Error 문을 Raise 클래스 모듈을 작성 하는 경우 오류를 생성 하는 데 유용 합니다. 예를 들어 합니다 Raise 메서드를 오류를 발생 시킨 소스에서 지정할 수 있습니다는 Source 속성을 오류에 대 한 온라인 도움말을 참조할 수 있습니다 및 등입니다.

개체에서 사용자 정의 오류를 반환 하는 경우 설정 Err.Number 을 오류 코드와 선택한 수를 추가 하 여를 VbObjectError 상수입니다. 예를 들어 오류 코드로 1051 개수를 반환 하려면 다음 코드를 사용 합니다.

Err.Raise(Number:=vbObjectError + 1051, Source:="SomeClass")

적용 대상

추가 정보