Interviews - C# Corner

Ankur Jain
C# - Difference between Throw and Throw ex in C# Asp.Net?
By Ankur Jain in .NET on Aug 18 2014
  • Ankur Jain
    Aug, 2014 18

    Throw: In Throw, the original exception stack trace will be retained. To keep the original stack trace information, the correct syntax is 'throw' without specifying an exception. Eg: try { // do some operation that can fail } catch (Exception ex) { // do some local cleanup throw; }Throw ex:In Throw ex, the original stack trace information will get override and you will lose the original exception stack trace. I.e. 'throw ex' resets the stack trace.Eg: try { // do some operation that can fail } catch (Exception ex) { // do some local cleanup throw ex; } }

    • 1
  • Dilip Bangar
    Apr, 2015 8

    If you use "throw" statement, it preserve original error stack information. If you use "throw ex" statement, stack trace of the exception will be replaced with a stack trace starting at the re-throw point.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS