嗔秤戻幣�哉膵�云利匈嬉蝕湊蛸賜�塋床四衲���萩晦編報炎嘔囚^泡仟 ̄云利匈�《超噌�殻窟�嵌虜隆輓麈觚翹瀘卉韮�仍仍�。� 烏御危列
昂昂慕汐 卦指云慕朕村 厘議慕尺 厘議慕禰 TXT畠云和墮 序秘慕杏 紗秘慕禰

VB2008貫秘壇欺娼宥(PDF鯉塀哂猟井)-及63嫗

梓囚徒貧圭�鮗� ○ 賜 ★ 辛酔堀貧和鍬匈��梓囚徒貧議 Enter 囚辛指欺云慕朕村匈��梓囚徒貧圭�鮗� ● 辛指欺云匈競何��
!!!!隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��




           generate an exception separate from any existing state that could be corrupted。 Once the manipulations have  

           been carried out�察�you integrate the objects into the global state using method calls that are extremely unlikely  

           to generate exceptions。 For those situations when you must manipulate existing state�察�use a  Finally handler�察 �

           so that the previous existing state can be re´created if necessary。 



           Filtering Exceptions 



           In all of the examples presented so far in this chapter�察�the Catch statement used the Exception type�此�



           Catch exception1 As Exception  



                 Exception will catch every exception。 


´´´´´´´´´´´´´´´´´´´´´´Page 149´´´´´´´´´´´´´´´´´´´´´´´

                               CH AP T E R   5   *    L E AR N IN G   AB O U T   V I SU A L   B AS IC   E X CE PT I ON   HA N D L IN G 127 



     In Figure 5´3�察�the IDE caught an exception�察�referencing NullReferenceException�察�which is  

a specific type of exception。 When you use it in a Catch statement�察�you will catch only null refer

ence exceptions。 

     By specializing the exception�察�you have the ability to filter which exception you want to  

catch。 For example�察�NotSupportedException will catch only instances of NotSupportedException  

exceptions。 Here is an example�此�



Try  

    Throw New NotSupportedException�─�There is no code;�� 

Catch ex As NotSupportedException 

End Try 



     If the code within the Try block threw an instance of Exception�察�the Catch block would not  

trigger�察�because the Catch block was looking for a specific exception type。  

     Exception types can be bined to provide specific filtering capabilities。 The specific  

exception type should be the first exception after the Try block�察�as in this example�此�



Try  

    ' 。 。 。 

Catch ex1 As NotSupportedException 

     ' 

Catch ex2 As Exception 

     ' 

End Try 



     By bining multiple exception filters�察�you don¨t need to figure out which kind of excep

tion is being thrown。 For example�察�without the filtering capabilities of a Catch block to catch  

NotSupportedException exception types�察�you would need to write this code�此�



Try  

    Throw New NotSupportedException�─�There is no code;�� 

Catch ex As Exception 

    If ex Is NotSupportedException Then 

        '。 。 。 

    Else  

        Throw ex 

    End If 

End Try 



     Table 5´1 lists mon exception types in the System namespace that you can throw or  

can be thrown。 There are many more exceptions�察�and you can even generate your own excep

tions by subclassing  Exception。  


´´´´´´´´´´´´´´´´´´´´´´Page 150´´´´´´´´´´´´´´´´´´´´´´´

128        CH AP T E R   5   *    L E A R N IN G   AB OU T   V I SU A L   B AS IC   E X C E P TI ON   H AN D L IN G 



           Table 5´1。  mon Exception Types 



           Exception                                  Description 



           Exception                                  Plain´vanilla exception�察�a general container for all exceptions。  

                                                      When you get one of these exceptions�察�look at the Message  

                                                      property for the exact details。 If you throw this type of excep

                                                      tion�察�it is important to supply an easy´to´understand string to  

                                                      the exception constructor。 



           ArgumentException                          Thrown if you call a method and one of the arguments is not  

                                                      valid。 Typically�察�in the Message property you can find the  

                                                      problem with the arguments。 If this exception is thrown�察�it is  

                                                      because the contents of the argument are wrong。 



           ArgumentNullException                      Thrown if you call a method where one of the arguments is  

                                                      a Nothing value。 This could be because you are passing the  

                                                      Nothing value to the method or one of the arguments has a  

                                                      Nothing value。 



           ArgumentOutOfRangeException                Thrown if you call a method where one of the arguments is  

                                                      not in the expected range。 While this exception sounds similar  

                                                      to ArgumentException�察�it is more specialized and targets  

                                                      whether an argument is in an acceptable range。 Check the  

                                                      documentation of the method or the method implementation  

                                                      on what the acceptable range is。 If you throw this exception�察 �

                                                      note the valid range in the error message。 



           ArithmeticException                        Thrown if a mathematical error is generated。 



           DivideByZeroException                      Thrown if you attempt to divide by zero。 



           FormatException                            Thrown if the format of the parameter is not correct。 For  

                                                      example�察�if a method expects a number to be formatted with  

                                                      a period and you use a ma�察�an exception is generated。 



           IndexOutOfRangeException                   Thrown if you attempt to reference an index of an array that  

                                                      would be beyond the limits of the array。 This exception is  

                                                      thrown if you have not allocated an array an
卦指朕村 貧匯匈 和匯匈 指欺競何 壘��1�� 家��1��
隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��
梁椣戻幣�� 梁心弌傍議揖扮窟燕得胎��傍竃徭失議心隈才凪万弌誌育断蛍�輌臆惨軼僑〃�燕慕得珊辛參資誼持蛍才将刮襲潜��範寔亟圻幹慕得 瓜寡追葎娼得辛參資誼寄楚署衛、持蛍才将刮襲潜填��