In this post I will try to explain the difference between throw and throw ex in Asp.Net C# Exceptions. My previous post Difference between dataset and datareader in Asp.Net C# exceptions.
Exceptions
Exceptions are always useful for dotnet developers, because we are able to provide a bug free application with the use of exception handlings.We need to find the actual exception, here throw will give the exception details.We are confusing whileusing the throw and throw ex in exceptions.Difference between "throw" and "throw ex" is, "throw" will provide the orginal exception which was available at first in stack and "throw ex" will provide the last exception message available in stack.
Syntax for "throw ex"
try
{
//If error occured go to catch and throw exception
}
catch (Exception ex)
{
throw ex;
}
Syntax for "throw"
try
{
//If error occured go to catch and throw exception
}
catch
{
throw;
}
Eg: While working in N layered architecture application, "throw ex" will be use in UI Layer and "throw" will be use in all other layers.So try this in your application and check the difference.
Output
In this post i tried to explain the difference between throw and throw ex in Asp.Net C# Exceptions. My previous post Difference between dataset and datareader in Asp.Net C# exceptions.
thanks for sharing this excellent information it's very useful to dot net learners.we are offering dot net online training if any body want to learn dot net plz visit the link....
ReplyDeleteDOT NET ONLINE TRAINING
I think this is among the most important information for
ReplyDeleteme. And i am glad reading your article.
First is to thank you for all this informative posts you give us for free; i bet all of us are happy.
ReplyDeleteSuch a great idea of yours! You have been a big help for me. Thanks a lot. more post for interesting topic. Great!
SAP training in Chennai
Thanku for sharing this nice post..
ReplyDeleteSAP HANA training in hyderabad,This is the best path You can Learn Complete Course with full fledge knowledge of SAP.
The blog gave me an idea about throw and throw ex. Thanks for sharing it
ReplyDeleteDotNet Training in Chennai
useful blog to read
ReplyDeletedotnet training institute
It was so good to read and useful to improve my knowledge as updated one.Thanks to Sharing.
ReplyDeleteInformatica Online Training | ETL Testing Online Training | Hadoop online Training
AvriqPrinter RepairPrinter InstalltionWifi trouble shooting
ReplyDeleteSoftware InstalltionGreatly composed article, if just all bloggers offered the same substance as you, the web would be a much better place.
Virus removal
ReplyDeleteNice post keep do posting The Info was too good, for more information regarding the technology Click
Amazon web Services Training
Devops training