You are on page 1of 5

Faculty of Computing and Informatics

Lesson 7 – Theory

Exception Handling
Learning Objectives

After studying this lesson, you should be able to:

• Understand and use exception handling


What is Exception Handling?

• An error condition during a program execution is called an exception


and the mechanism for resolving such an exception is known as
exception handling.

• We can put all T-SQL statements into a TRY BLOCK and the code for
exception handling can be put into a CATCH block.
Error handling overview
• Error handling in SQL Server gives us control over the Transact-SQL
code.

• For example, when things go wrong, we get a chance to do something


about it and possibly make it right again.

• SQL Server error handling can be as simple as just logging that


something happened, or it could be us trying to fix an error.

• It can even be translating the error in SQL language because we all


know how technical SQL Server error messages could get making no
sense and hard to understand.

You might also like