Difference Between Throw And Throw(Ex) In C#

C# provides the facility to handle exception using try and catch block .

C# provides the facility to handle exceptions using the try and catch block. There are two ways --  you can either use throw(ex) method or the simpler throw method, as below. 

First Way 
  1. try  
  2. {  
  3. }  
  4. catch(Exception ex)  
  5. {  
  6.    throw;  
  7. }  
Second way
  1. try  
  2. {  
  3. }  
  4. catch(Exception ex)  
  5. {  
  6.    throw(ex);  
Now, the question arises -- which one is better?

Here is the screenshot of a simple program.

C# 
The Throw method throws the current exception only while the Throw(ex) method will reset your stack trace so the error will appear from the line where Throw(ex) is written. Since Throw does not reset the stack trace, you will get the information about the original exception. Throw (ex) gives the following Exception Message.
 
at ConsoleApp1.Program.Main(String[] args) in D:\INTW\Console\ConsoleApp1\ConsoleApp1\Program.cs:line 19

C# 

And, Throw sends this Exception Message.

at ConsoleApp1.Program.DevideByZero(Int32 i) in D:\INTW\Console\ConsoleApp1\ConsoleApp1\Program.cs:line 26

at ConsoleApp1.Program.Main(String[] args) in D:\INTW\Console\ConsoleApp1\ConsoleApp1\Program.cs:line 19
 
C# 

So, you can see in the above image, we have got full stack trace information where the actual exception is called at line 26 and again rethrown at line 19.

While in the first screenshot, you can see there is only information about line 19. It does not show a full-stack trace. So, I will recommend you to always use Throw method.