Can VB.NET catch exceptions without defining a local exception variable?
In C# you can do this:
try
{
// some code here
}
catch (MyCustomException)
{
// exception code here
}
catch (Exception)
{
// catches all other exceptions
}
Notice the catch (Type)
instead of catch (Type myVariable)
. Is this possible with VB.NET, or do you always have to declare a va开发者_StackOverflow社区riable when you catch exception types, like so:
Try
...
Catch var As NullReferenceException
...
Catch var As Exception
...
End Try
Gotta be declared in vb.net.
In fact when you type in try
your ide should put in the exception type and format it.
like so:
Try
Catch e As Exception
End Try
In case a search engine brings anybody else here...
C# also has a syntax where you don't have to specify the type:
try { }
catch { }
I believe that will also catch unmanaged exceptions that do not derive from System.Exception. VB.NET can do the same:
Try
Catch
End Try
精彩评论