THROW in Error Handling: T-SQL Features in SQL Server 2012

THROW in Error Handling: T-SQL Features in SQL Server 2012

In my previous posts we have seen what is Transact-Sql in sql server and What are new top features of T-Sql in server. This is one of the best sql server interview Questions and answers. 

  In previous versions, RAISERROR was used to show an error message. RAISERROR requires a proper message number to be shown when raising any error. The message number should exist in sys.messages. RAISERROR cannot be used to re-throw an exception raised in a TRY...CATCH block.

·        Unlike RAISERROR, THROW does not require that an error number to exist in sys.messages (although it has to be between 50000 and 2147483647). All exceptions being raised by THROW have a severity of 16.

·        THROW even allows for re-throwing an exception caught in a TRY...CATCH block, which RAISERROR was not able to handle

  SELECT ‘Using Throw’
  SELECT 1 / 0 

(1 row(s) affected)
 (0 row(s) affected)
Msg 8134, Level 16, State 1, Line 3
Divide by zero error encountered.

If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar