Error Handling is very essential in every programming language, similarly in SQL server we have multiple built in functions to handle errors that may occur in TSQL code. This lab is divided into six exercises explaining different types of Error Handling functions. In first exercise we will learn to detect errors using @@ERROR system variable. In second exercise we will understand structured error handling using TRY…CATCH blocks. In third exercise we will learn to raise user defined errors using @@RAISERROR system variable. In fourth exercise we will learn to throw errors using THROW function. Fifth exercise is Self-Assessment, where a problem is given and you to solve by yourself. Sixth exercise presents the TSQL challenge that needs to be solved (slightly tougher than self-assessment).
Exercise 1: Detect the errors using @@ERROR
Exercise 2: Understanding structured error handling using TRY… CATCH
Exercise 3: Raising user-defined errors using @@RAISERROR
Exercise 4: Throw an error using THROW exception
Exercise 5: Self-Assessment
Exercise 6: T-SQL Challenge