I have the following code:
try
{
OnInitialize();
}
catch (PageObjectLifecycleException exception)
{
exception.OldLifecycleState = CurrentLifecycleState;
exception.RequestedLifecycleState = LifecycleState.Initialized;
throw exception;
}
I catch an exception, add some more data to it, and rethrow it. Resharper warns me (correctly) that a rethrow is possibly intended and suggests changing it to:
throw;
But I’m wondering: Will this correctly rethrow the modified exception or the unmodified original one?
Edit: In response to the “Try it and see” comments: I am new to C#, comming from C++. In C++ you often find undefined behaviour in corner cases like this and I am interested in whether what I want is really how it officially works.
It will throw the reference to the modified exception.
However I am not sure whether this is good programming style. Consider creating a new exception and add the PageObjectLifecycleException as its inner exception. This way the handling code can be sure whether it has the correct additional information or not.