Dilshad Ashraf

Dilshad Ashraf

  • 1.5k
  • 245
  • 6k

What is difference between "throw" and "throw e"

Aug 18 2020 10:01 AM
Hi All,
 
I hope you all are doing well.
 
I have a question regarding throw and throw e,
 
I want to more clear on this exception topic.
 
I have written a simple program for the exception, program is below:
  1. using System;  
  2. public class Program  
  3. {  
  4.    public static void Main()  
  5.    {  
  6.        try{  
  7.             Int64 a = Convert.ToInt64("abc");  
  8.             Console.WriteLine(a);  
  9.          }  
  10.       catch(Exception e){  
  11.          throw ;  
  12.       }  
  13.     }  
  14. }  
Exception:
 
Run-time exception (line 12): Input string was not in a correct format.
Stack Trace:
[System.FormatException: Input string was not in a correct format.]
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToInt64(String value)
at Program.Main() :line 12
  1. try{  
  2.     Int64 a = Convert.ToInt64("abc");  
  3.     Console.WriteLine(a);  
  4. }  
  5. catch(Exception e){  
  6.     throw ;  
  7. }  
Exception:
 
Run-time exception (line 11): Input string was not in a correct format.
Stack Trace:
[System.FormatException: Input string was not in a correct format.]
at Program.Main() :line 11
 
I have seen only one difference when I am throwing with "e" getting full trace details, when not using only getting single line error details.
 
Is there any more difference or any other points, and what to use, "throw e" or "throw".
 
Thanks in advance.

Answers (2)