There are two diffrences
First you are correct the 2nd one causes a new exception to be thrown with a new stack trace. This will cause you to loose valuable debugging information and should never be done. The correct way to do the 2nd example would be
try
{
... some code ...
}
catch (Exception) //You can include the "ex" if you need it in your cleanup code
{
... some cleanup code ...
throw; //Don't use the "ex" here
}
The 2nd difference is there are a very vary small number of exceptions that the first example will catch that the 2nd example will not. Mainly these exceptions are ones thrown from non CLR complient code. There is no way to throw a non Exception
derived exception from C# code.
One thing if you want to add additional information to the exception before you bubble it up you can throw a new exception and put the old exception as the InnerException
try
{
... some code ...
}
catch (Exception ex)
{
... some cleanup code ...
throw new MyCustomException("Some useful information", ex);
}