Try Catch What can you do (3)?

In the previous example, is equipped with a Try a Catch, in fact, a lot can be used with a Try Catch, like this approach can be processed differently according to different exceptions.


          In the previous example, is equipped with a Try a Catch, in fact, a lot can be used with a Try Catch, like this approach can be processed differently according to different exceptions.

For example, treatment in the Try block things, including the Socket and data link, and we hope to be able to catch up SockectExecption and SqlException take a different strain scheme, Try Catch block can be written like this:
Try Catch socketEX of As SocketException            ' If the Socket execption do happen Catch SqlEx of as SqlException             'if Sql execption do happen Catch EX of as Exception              ' execption do if other things happen the Finally End the Try it occurs when the Socket execption, will perform "If there is Socket execption the right thing "; but not executed" if the other execption happen to do "and" if Sql execption happen to do things. " Catch arrangement of this is in order, when two Catch relevant when small range Execption must be in front, in the previous example, if we changed the Try Catch EX of As Exception Catch socketEX of As a SocketException Catch SqlEx of As the SqlException Finally
           






 

 

 

 


 

 

 

 

 
End Try
 
this compiler will issue a warning, VB.NET compiler even without the red line will appear, telling you unreachable Catch socketEX As SocketException with Catch SqlEx As SqlException two blocks, because Catch ex As Exception will be cut to almost column All exceptions.
 
Try Catch is not very interesting? Try Catch good use not only in dealing with things related to the exceptions, if more attention Exception bring us the news, and procedures for improving the structure of the program will be helpful to write.

Original: Big Box  Try Catch help you to do (3)?


Guess you like

Origin www.cnblogs.com/chinatrump/p/11458547.html