Error Handling in Sql server 2005

Hi,

Error handling is Process of Trapping the Error in any application. In SQL server until 2005 it is very difficult to get the source error and shat causes the exception. To abort the Exception We can use the Below statement

SET XACT_ABORT ON to abort the Error and continue with Next statement

To error the Error Description of the Error we can many statement in SQL SERVER 2005.

To check the Severity of the Error message and its categories you can call the below System Table

There you can see the Pre-defined Error message and its Severity

select * from sys.messages

Severity will be Logged in the System Event Log.

If the Severity is more then it will be displayed as Red in color

We can also give our own error message..

Error_Number() will return the Error number for the Error message

Error_Message() will return the Error message that is occured

Error_Severity() will return the severity of the Error.

Error_procedure() will return the name of the stored procedure or trigger where an error occurred

Error_State() will return the state number of the error that caused

Below is the Syntax of the Exception handling in SQL SERVER 2005



BEGIN TRY

BEGIN TRANS

Some Statements

COMMIT TRANS

END TRY

BEGIN CATCH

PRINT ERROR_NUMBER()

END CATCH



Regards
JK


Comments

Author: Parvathi S30 May 2009 Member Level: Silver   Points : 1

I think In sqlserver nested try catch block is not possible.
Can you tell me whether it is possible or not.

Regards,
Parvathi.

Author: D.Jeya kumar(JK)31 May 2009 Member Level: Gold   Points : 1

Hi

we can include Nested Try catch in sql server

try catch clock can be placed inside other TRY and CATCH blocks. When an error occurs within a nested TRY block, program control is transferred to the CATCH block that is associated with the nested TRY block.

Regards
JK

Author: Ultimaterengan03 Jun 2009 Member Level: Gold   Points : 0

good one

thanks



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: