Introduction
In order to improve error handling in TSQL scripts Microsoft has introduced throw statement in SQL Server 2012. This feature will help the database developers to handle errors more effectively.
Advantages of Using Throw Statement in SQL Server 2012
- In sys.messages it is not required to have error_number parameter to exist.
- Statement just before the THROW statement must be followed by (;) semicolon.
- The severity level of the exception is always set to 16.
THROW SYNTAX AS MENTIONED IN MSDN
Sample TSQL Script to Demo THROW Statement
Execute the below sample TSQL script which has a Demo of THROW statement of SQL Server 2012.
Error Message
In the above snippet you could see that the error message is re-thrown by the SQL Server.
Reference: - Throw Statement
Conclusion
It is recommended to use THROW statement in new development work within the TRY...CATCH statement.
Read more: http://www.mytechmantra.com/LearnSQLServer/Error-Handling-Using-Throw-Statement-in-SQL-Server-2012/#ixzz3h4dDDmn8
Follow us: @MyTechMantra on Twitter | MyTechMantra on Facebook