Thursday, August 29, 2013

C#: Difference between “throw” and “throw ex” in C# .Net Exception

In day to day development, we all are very familiar with Exception  handling. We pretty much all know that we should wrap the code which may cause for any error in try/catch block and do something about error like give a error message to end user. Here I am not going to explain about Exception handling in C#. Instead I am going to talk about a particular aspect of Exception  handling, which is "throw" vs "throw ex".

You can also find my other articles related to C#ASP.Net jQuery, Java Script and SQL Server. I am writing this post because I was asked this question recently in a interview and unfortunately I didn't  know the answer. So I am posting this for those guys who uses "throw" and "throw ex" frequently but don't know the differences (not all,some knows).

Difference between “throw” and “throw ex”

Take a look on the below code snippest-
throw ex throw

try
{
   //Code which fails and raise the error
}
catch (Exception ex)
{
   throw ex;
}

try
{
   //Code which fails and raise the error
}
catch (Exception ex)
{
   throw;
}

Wednesday, August 14, 2013

LINQ- Difference between First and FirstOrDefault- First vs FirstOrDefault

In my previous post Single vs SingleOrDefault, we talk about Single and SingleOrDefault method and difference between these methods. In this post we are going to explore two more extension methods First and FirstOrDefault.


You can find some other useful topics and posts here. Below is a chart explaining about First() and FirstOrDefault(). You can easily differentiate these methods from this chart. I have also given examples of each method.

Monday, August 12, 2013

LINQ- Difference between Single and SingleOrDefault- Single vs SingleOrDefault

In today's development, we all are frequently users of LINQ. So In this post and some incoming posts, I will try to explain about some LINQ's extension methods that seems trivial, but can really helpful to improve your code by making it easier.

Here, In this post I am going to explain you about Single and SingleOrDefault method and difference between these methods.

You can find some other useful topics and posts here. Below is a chart explaining about Single() and SingleOrDefault(). You can easily differentiate these methods from this chart. I have also given examples of each method.

Tuesday, August 6, 2013

SQL Server- User Defined Function to Parse HTML- Strip HTML -Without Using Regular Expression

This is a simple tip post. In this post I will show you a user defined function in SQL Server which parse the HTML and retrieve the Text only from it.

In previous posts, I explained Case Sensitive Search in SQL Server, Check Primary Key Existence in Table, Reset Identity Column in SQL Server, Insert Values into Identity column, Identity Column in SQL Server , STUFF Function, LEN Function, UNICODE Function, LEFT Function, CHARINDEX Function, Simple script to backup all SQL Server databases, Table-Valued Parameters and some other articles related to SQL ServerASP.Net, C#.

Following UDF takes the HTML as input and returns Text only from it. Please note you need to replace all the single quotes (if any) with two single quote (not double quote) in HTML before passing it as input to function.
^ Scroll to Top