Given the following code in C #:
public void CatchExceptionThenThrow()
{
try
{
StartThings();
}
catch (Exception)
{
throw;
}
}
I converted this to VB as such using the vnet.net dotnetfiddle converter:
Public Sub CatchExceptionThenThrow()
Try
StartThings()
Catch As Exception
Throw
End Try
End Sub
This results in a compilation error:
Catch As Exception
Expected end expected
Then I change this to:
Public Sub CatchExceptionThenThrow()
Try
StartThings()
Catch ex As Exception
Throw
End Try
End Sub
But this creates the warning "variable declared but never used." How do I go throwing rather than throw exing in VB without receiving a warning while maintaining the integrity of the stack trace, as in the first C # example?
. , try/catch , try/catch. , , , ( ) .
- throw vs throw ex, , VB - VB .
, , , . ( ): https://dotnetfiddle.net/741wAi