????? ????? ??????????? ?? 2005 Visual Basic ?? Visual Basic .NET

?????? ????????? ?????? ?????????
???? ???????: 301283 - ??? ???????? ???? ????? ????? ??? ???????.
?????? ??? ????? Microsoft Visual C# 2005 ? Microsoft Visual C# .NET ?? ??? ???????? ???? 308345.

?????? ??? ????? Microsoft Visual Basic 6.0 ?? ??? ???????? ???? 191474.
????? ???? | ?? ????

?? ??? ??????

??????

catching ???? ?????? ?? ??????????? ???? ????? ??????. ???? ??? ??????? ????? ??????? ???? ???????? - catch-??????? ???? ???????. ?? ???? ???????? - catch-??????? "?????" ???? ??? ??? ??????? ?????? ??? ???? ?????? ???? ???????.

???? ???????? - catch-??????? ????? ?? ??????? ???????:
  • ??? ??? ?? ?????? ?????? ?? ???? ???? ??????? ???? ???? ????????.
  • ??? ?? ????? ??????? ????? ???? ?????? ?? ???? ???????? ????? ??????? ???????? ??????? ?? ????? ????????.
  • ??? ?????? ????? ????????? ???????? ???????? ?? ???? ??????? ?? ???? ????? ????? ????? ??? ??? ???????. ???? ??????? ????????.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • Microsoft Windows Server 2003 Microsoft Windows 2000 Professional Windows 2000 Server Windows 2000 ?????? ???? ?? ???? Microsoft Windows NT 4.0
  • Microsoft Visual Basic 2005 ?? Microsoft Visual Basic .NET

?????? ???? ?????

  1. ????? "????? ???? ????" ???? ?? Visual Basic 2005 ?? ?? Visual Basic .NET.
  2. ?? ??????? ??????? Sub ????? ????? ????????? ???????? ??????. ???? ?????? ?????? ? ????? ????????? ????? wherein ???? ????? "?" ????.
    ' This code generates an exception.
    	Console.WriteLine("We're going to divide 10 by 0 and see what happens...")
    	Console.WriteLine()
    
    	Dim i as Integer = 10
    	Dim j as Integer = 0
    	Dim k As Integer = i/j ' Error on this line.
    					
  3. ???? ??????? F5 ???? ?????????.
  4. ?????? ????? catch ???? ??? ????????? ???????? ??????? ?????. ???????? ???????? ??????? catches ???? ????? ??? ?? ????????? ???????? ????? ????? ??? ????. ??????? ????????? ???????? ?? ??????? ??????? Sub ???????? ???????? ???????.
    ' This code shows how to catch an exception.
    Try
    	Console.WriteLine("We're going to divide 10 by 0 and see what happens...")
    	Console.WriteLine()
    
    	Dim i as Integer = 10
    	Dim j as Integer = 0
    	Dim k As Integer = i/j ' Error on this line. Control jumps to the catch block.
    Catch
    	Console.WriteLine("An error occurred.")
    End Try
  5. ???? CTRL + F5 ?????? ???????. ???? ???? ????? ????? ?? ???? ??????.
  6. ??? ??? ??? ????? ?? post-processing ????? ??? ?? ??? ??? ????? ?? ??? ? ?????? ??? ??????? ?? ??????? ???? - catch-???????. ?? ????? ??????? ?? ??????? ??? ?????? ????? ????????? ???????? ? ??? ????? ?? ???????. ???? ????????? ???????? ??????? "??? ??????? ??? ????? ?????" ?? ???? ???? ??????? ??? ??? ?? ???? ???. ??????? ??? ??????? Sub ???????? ???????? ???????.
    ' This code shows how to catch an exception.	
    Try
    	Console.WriteLine("We're going to divide 10 by 0 and see what happens...")
    	Console.WriteLine()
    
    	Dim i as Integer = 10
    	Dim j as Integer = 0
    	Dim k As Integer = i/j ' Error on this line. Control jumps to the catch block.
    
    Catch
    	Console.WriteLine("An error occurred.")
    Finally   ' This section is performed regardless of the above processing.
    	Console.WriteLine()
    	Console.WriteLine("This statement is always printed")
    End Try
    					
  7. ???? CTRL + F5 ?????? ???????.
  8. ???? ??????? ???? ????????? ?? ??????? ?????? ??????? ?????? ?????????. ?? ??????? ??? ??????? ???? ???? ?? ?????? ?? ????? ????????? "??" ???? "??" ??????? ???? ??? ??? ???????. ???? ?? ???? ??? ????????? ????? ?????? ???? ????? ????? ?????? ????????? ?? ????? ??? ???? ???? ???????? ????? ??. ????? ?????? catches ??????? ?????? ????? ??? ?????. ??? ??? ? ????? ??????? ????????? ???????? ?? ??????? Sub ??????? ?? ????????? ???????? ???????.

    ???? 1
    ' This code shows how to catch an exception.
    Try
    	Console.WriteLine("We're going to divide 10 by 0 and see what happens...")
    	Console.WriteLine()
    
    	Dim i as Integer = 10
    	Dim j as Integer = 0
    	Dim k As Integer = i/j ' Error on this line. Control jumps to the catch block.
    
    Catch e As Exception  ' Perform code that deals with the exception
                          ' or informs the user what occurred.
    	Console.WriteLine("The following error occurred:")
    	Console.WriteLine(e.ToString())  ' Print the error message to the user.
    
    Finally   ' This section is performed regardless of the above processing.
    	Console.WriteLine()
    	Console.WriteLine("This statement is always printed")
    End Try
    					
    Example 2
    ' This code shows how to catch an exception.
    Try
    	Console.WriteLine("We're going to divide 10 by 0 and see what happens...")
    	Console.WriteLine()
    
    	Dim i as Integer = 10
    	Dim j as Integer = 0
    	Dim k As Integer = i/j ' Error on this line. Control jumps to the catch block.
    
    Catch e As Exception  ' Perform code that deals with the exception
                          ' or informs the user what occurred.
            Console.WriteLine("The following error occurred:")
            Console.WriteLine( e.Message )     ' Print the error message.
            Console.WriteLine( e.Source )      ' Name of application or object
                                               ' that caused the error
            Console.WriteLine( e.StackTrace )  ' String that contains the stack 
                                               ' trace for this exception
    Finally   ' This section is performed regardless of the above processing.
            Console.WriteLine()
            Console.WriteLine("This statement is always printed")
    End Try
    					
  9. ??? ??? ?????? ???? ??????? ?? ?????? ???? ??????? ??? ????. ??? ???? ??? ??? ???? ?????? ???????? ??? ????????? ???? ? ????? ????? ????????? ???????? ?? ?????? ????? ????. ?? ????? ??????? ??? ??? ?????? ?????? ???? ??????????? ?? ??????? ???? ?????. ???? ????? ?????? ???.
    Module Module1
    Sub Main()
    
    ' Attempt to do some file processing.
    ' This can cause a number of potential exceptions.
    ' Note that you can use the specific exceptions to get extra information about that exception,
    ' but this example focuses on showing control execution for those exceptions.
    
    Try
    	File.Create("c:/temp/test.txt")  ' Can fail for a number of reasons
    
    Catch ioe As System.IO.IOException ' This error may occur if the Temp folder does not exist.
    	Console.WriteLine("An IO error occurred. The c:\temp folder does not exist")
    
    Catch se As System.Security.SecurityException ' You do not have the appropriate permission
                                                  ' to take this action.
    	Console.WriteLine("You don't have the security permissions to take this action!")
    
    Catch e As Exception    ' Catch all other exceptions.
    	Console.WriteLine( e.ToString() )  ' Print the standard exception information.
    End Try
    End Sub
    End Module
    ??? ?? ????? ??????? ????????? ??????? ?? ??? ?????? ?? ?? ?? ?? ???? ???? ???????. ??? ??? ???? ?? ??? ??????? IO ????? ???? ????? ??? ???? ??? ????? ??? ???? ????????? ????? ??.

?????

????? ?? ?????????? ???? Microsoft .NET Framework ?????? ????? ??????? (SDK).

???????

???? ???????: 301283 - ????? ??? ??????: 15/?? ??????/1427 - ??????: 5.5
????? ???
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
????? ??????: 
kbmt kbvs2005swept kbvs2005applies kbhowtomaster KB301283 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????301283

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com