比方說,我們有一個結構,像這樣:嵌套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