Skip to main content

Posts

Showing posts with the label Try Catch in SQL Server Stored Procedures

How to Handle Error or Exception in SQL? When you use @@Error and TRY-CATCH?

Today's, I am going to share the code sample for exception handling in SQL Server; The SQL Server exception handling is very similar to the Microsoft C# and C++ etc. Error Handling Mechanism :- The two types of error handling in SQL Server that is 1.       @@ERROR 2.       TRY CATCH Block When we should use @@ERROR? 1.       While executing any stored procedures 2.       In the SQL statements like Select, Insert, Delete and Update etc. 3.       In the Open, Fetch Cursor. When we should use Try Catch Block? The Try Catch Block is generally used where want to catch errors for multiple SQL statements. In the SQL Server, The  TRY CATCH  are catches all errors and store in the @ ERRORS  variable and raise the errors using the  RAISERROR (). Following functions are used in CATCH block, ...