logo
  • Home
  • My Works
  • Downloads
  • Personal
  • Guest Book
  • About Me

More care on while re-throwing exceptions in .NET

Published by Rafeeque B Muhammad on Wednesday, February 3, 2010 12:00 AM
Updated on Wednesday, February 3, 2010 12:00 AM


I am not sure you have noticed the difference between throw; and throw ex;. Please look at this example,

class Program

    {

        static void Main(string[] args)

        {

            try

            {

                Method1();

            }

            catch (Exception ex)

            {

 

            }

        }

 

        public static void Method1()

        {

            try

            {

                Method2();

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

 

        public static void Method2()

        {

            Method3();

        }

 

        public static void Method3()

        {

            throw new Exception("Method3");

        }

    }

In method1 i am just trying to catch the exception ex and re-throwing again the same. If you will do so you will miss something in the stack trace.  Here you will get only Main and Method1, don’t show the methods Method2, M3thod3 which you have invoked.

Technical Articles

  • All
  • .NET Framework
  • ASP.NET
  • C#
  • Win Forms
  • WCF
  • SharePoint(WSS 3.0)
  • SQL Server
  • TSQL
  • Oracle
  • PL/SQL
  • Performance and Tuning
  • Application and Tools
  • Outlook programming
  • HTML/HTML5/XHTML/DHTML/JAVAScript/CSS
  • Windows Services
  • Web Services
  • Security
  • Web
  • General
  • Architecture

Technical Books

  • All
  • C# Threading
  • WCF

Other Links

  • Important Links

Techies Craft © 2014 | Privacy Policy