c# (Csharp) interview questions and answers:-What is the difference between Throw and Throw ex ?

c# (Csharp) interview questions and answers:-What is the difference between Throw and Throw ex ?


In this video will try to understand what is the difference between Throw and Throw ex In order we understand the difference have created a simple console application. This console application has two methods Method1 and Method2 In Method1 I am creating an exception object I have just put a simple string in the exception I am throwing this exception object by using the throw keywords If somebody calls this Method1 It will throw up an exception The control will then come to this catch and from catch I am doing a Throw This Method1 () is called from Method2 From Method2 it will actually invoke Method1 () This Method2 catches exception and does a Throw. It just having a throw keyword without the ex This Method2 later invoked from this static void main function This Method2 In this static void main () it is caught In the catch we are displaying StackTrace The StackTrace property helps to display complete information of the error Right from the source to the current method If you are displaying the StackTrace information here, it will display The error was initiated by Method1 or the source of the error was Method1 Then it was propagated to Method2 And then was set to send to the main method StackTrace displays a complete history of right from where the error has occurred till the current method on which your current data need in your code We have main method The main methods calls the Method2 and the Method2 calls the Method1 In Method1 we are initiating a Method1 This thrown back to Method2 It is caught in the main method where we are displaying StackTrace information If you are only using Throw keyword The complete StackTrace information right from the source the error was originated till the method on which you will display the Stack information will be displayed The complete stack information will be propagated right from Method1 till the Main I am using Throw in my Method2 here If I run this Its giving a complete stack information saying The error started from Method1 It was then propagated to Method2 And finally the error is displayed on the Main method If I change this Throw to Throw ex This information is very less as compared to previous one When we ran it by using the Throw It is not displaying the Method1 In Method2 where you said Throw ex from that Method only it has displayed the stack information, it has bypassed all the other information which was sent from Method1 The difference between Throw and Throw ex is In throw the complete stack information is propagated right from the source till the caller while when we use Throw ex It only displays the partial information of the stack error I hope you enjoyed this video. In this video we were trying to understand What is the difference between Throw and Throw ex? Whatever video you have seen is just a glimpse of what we have done In case you are interested in our video package go to www.questpond.com Call on this number and you can ask the dvd package what we have We have covered everything what a developer wants Right from basics of ASP.NET, Object Oriented Programming, SQL Server to New technologies like WCF, Silverlight, LINQ, Azure, Entity Framework Also have UML, Architecture, Estimation Project Management Complete Invoicing project end to end which is covered We have covered Server product both for SharePoint 2007 as well as for 2010 We have lot of best practices video on SQL Server etc This complete package you will get from the www.questpond.com In the same way as compare to the videos we also have one more product with us i.e our interview question books We have different kind sof interview question books right from .NET interview questions to SQL Server interview questions SharePoint interview questions, Biztalk interview question etc In case you are interested in the books part call on these numbers as per the location Keep enjoying the videos keep seeing our site Thank you very much

9 thoughts on “c# (Csharp) interview questions and answers:-What is the difference between Throw and Throw ex ?

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *