如果TypeOf ex是SpecificExceptionIWant那么 .... 具体例子: D as a Integer = 1,b As Integer = 0,c As Integer 尝试 c = a \ b Catch ex As Exception 如果TypeOf ex是DivideByZeroException那么 MsgBox(不要惊讶) 否则 MsgBox(Wething weIRD) 结束如果 结束尝试 这就像寻找特定的Err一样。 VB6中的数字',这是我怀疑你正在寻找的。 - Larry Lard 回复团体请 Its type. If TypeOf ex Is SpecificExceptionIWant Then.... Concrete example: Dim a As Integer = 1, b As Integer = 0, c As Integer Tryc = a \ bCatch ex As ExceptionIf TypeOf ex Is DivideByZeroException ThenMsgBox("No surprise")ElseMsgBox("Something WEIRD")End IfEnd Try This is exactly like looking for specific Err.Number''s in VB6, which iswhat I suspect you are looking for.--Larry LardReplies to group please \\\ 如果TypeOf ex是FooException那么 ... ElseIf TypeOf ex是GooException然后 ... .... 结束如果 /// - 或 - \\\ Select Case True Case TypeOf ex FooException .. 。 案例类型以前是GooException ... ... 结束选择 /// 请注意,FxCop会抱怨捕获块,它们会捕获通用的 异常类型。但是,这个规则是有争议的,可能会改变/删除。关于这个问题的德国文章: 神话:Catch(例外)是什么b?se < URL:http://www.die.de/博客/ PermaLink.aspx?guid = c0d9a5d0-b12d-4995-8447-94040a932dc9> - MS Herfried K. Wagner MVP< URL:http://dotnet.mvps.org/> VB< URL:http://classicvb.org/petition/> \\\If TypeOf ex Is FooException Then...ElseIf TypeOf ex Is GooException Then.......End If/// - or - \\\Select Case TrueCase TypeOf ex Is FooException...Case TypeOf ex Is GooException......End Select/// Note that FxCop will complain about ''Catch'' blocks which catch the genericexception type. However, this rule is controversial and may bealtered/removed. German article on this issue: Mythos: Catch( Exception) ist b?se<URL:http://www.die.de/blog/PermaLink.aspx?guid=c0d9a5d0-b12d-4995-8447-94040a932dc9> --M S Herfried K. WagnerM V P <URL:http://dotnet.mvps.org/>V B <URL:http://classicvb.org/petition/> 那是因为没有 - 你可以直接检查Exception对象的类型 : Catch ex as Exception 如果TypeOf ex是ArgumentException那么 DirectCast(ex,ArgumentException).thingamydoodle 结束If HTH, Phill W. That''s because there isn''t one - you can simply examine the Typeof the Exception object directly: Catch ex as ExceptionIf TypeOf ex Is ArgumentException ThenDirectCast( ex, ArgumentException).thingamydoodleEnd If HTH,Phill W. 这篇关于如何确定我在CATCH中获得的WHICH异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 10:17