在C#中,你可以這樣做:VB.NET能否在不定義本地異常變量的情況下捕獲異常?
try
{
// some code here
}
catch (MyCustomException)
{
// exception code here
}
catch (Exception)
{
// catches all other exceptions
}
通知的catch (Type)
而不是catch (Type myVariable)
。這可能與VB.NET,或者你總是當你抓到的異常類型來聲明一個變量,像這樣:
Try
...
Catch var As NullReferenceException
...
Catch var As Exception
...
End Try
和VB.NET不給你的*變量「EX」聲明,但從未使用*警告其如果你聲明它,不要你將獲得在C#不會使用它。 – 2011-04-06 18:14:06
是的,Visual Studio會這樣做,這正是我所害怕的。我只是把它放在我的「C#更好的事情列表」上。謝謝。 :) – qJake 2011-04-06 18:18:40
@SpikeX - VB.net真的很羅嗦。 – JonH 2011-04-06 18:19:06