Error Function used in CATCH block

In this article i described various error functions in sql server 2008
  • 3778

Introduction

TRY..CATCH block allows you to specify two SQL statements. The code to be executed is enclosed in TRY block and the code for handling error is enclosed under CATCH block. If the code under the TRY block is failed then control automatically jumps under the CATCH block. CATCH block is used to catch errors. In CATCH block there are various functions which can be specified in Catch block:

1. Error_Number Function

Error_Number returns the error number which caused the execution of code under CATCH block.

Output:

ErrorNumber.jpg

2. Error_Severity Function

Error_Severity Function returns the severity level of the error  which caused the execution of logic under CATCH block.

Output:

ErrorSeverity.jpg

3. Error_State Function

Error_State Function returns the state number of the error which caused the execution of logic under CATCH block.

Output:

ErrorState.jpg

4. Error_Line Function

Error_Line Function returns the line number of code where the error occurs. This function is very useful in code having large number of lines. This function does not accept any parameter.

Output:

ErrorLine.jpg

5. Error_Message Function

This function returns the message text of the error occured  in TRY block. This function does not accept parameters.

Output:

ErrorMessage.jpg


Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.