比方说,我们有一个结构,像这样:嵌套Try/Catch块是一个坏主意吗?
Try
' Outer try code, that can fail with more generic conditions,
' that I know less about and might not be able to handle
Try
' Inner try code, that can fail with more specific conditions,
' that I probably know more about, and are likely to handle appropriately
Catch innerEx as Exception
' Handle the inner exception
End Try
Catch outerEx as Exception
' Handle outer exception
End Try
我已经看到了一些观点认为嵌套Try
块这样的鼓励,但我无法找到任何具体原因。
这是错的代码?如果是这样,为什么?
不确定片段真的有多准确。但是当你抓到异常时,你并不知道你真的知道了什么。它可以是*任何*。考虑利用VB.NET支持的When子句。 – 2011-01-26 00:07:19