M
Mike Schilling
These two fragments do not act identically:
(1)
catch(Exception ex)
{
...
throw ex;
}
(2)
catch (Exception ex)
{
...
throw;
}
In (1), ex.StackTrace is reinitialized, so the exception will appear to have
originated inside the fragment. That is, the MSIL throw instruction is
generated.
In (2) ex.StackTrace is not reinitialized, so the exception will appear to
have originated wherever it was last thrown. That is, the MSIL rethrow
instruction is generated.
I couldn't find any place this is documented.
(1)
catch(Exception ex)
{
...
throw ex;
}
(2)
catch (Exception ex)
{
...
throw;
}
In (1), ex.StackTrace is reinitialized, so the exception will appear to have
originated inside the fragment. That is, the MSIL throw instruction is
generated.
In (2) ex.StackTrace is not reinitialized, so the exception will appear to
have originated wherever it was last thrown. That is, the MSIL rethrow
instruction is generated.
I couldn't find any place this is documented.