How to Handle the exceptions in Sqlsrver 2005??

Answer Posted / neetu

In SQLSERVER 2005 exceptions are handle by using RaisError
with Try catch like in other prog languages.
Begin Try

End try

Begin Catch

End Catch
BEGIN TRY

RAISERROR ('Yaa, I ma the problem', 16,1)

END TRY



BEGIN CATCH

SELECT ERROR_NUMBER() as ERROR_NUMBER,

ERROR_SEVERITY() as ERROR_SEVERITY,

ERROR_STATE() as ERROR_STATE,

ERROR_MESSAGE() as ERROR_MESSAGE

END CATCH



ERROR_NUMBER() returns the number of the error.
ERROR_SEVERITY() returns the severity.
ERROR_STATE() returns the error state number.
ERROR_PROCEDURE() returns the name of the stored procedure
or trigger where the error occurred.
ERROR_LINE() returns the line number inside the routine that
caused the error.
ERROR_MESSAGE() returns the complete text of the error
message. The text includes the values supplied for any
substitutable parameters, such as lengths, object names or
times.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I find my localdb version?

486


what is difference between view and Dip.

1991


What is the user of Primary key?

575


Can we perform backup restore operation on tempdb? : sql server database administration

582


What is acid db?

500






What are synonyms?

522


How to transfer data from a cursor to variables with a "fetch" statement?

580


What is use of attribute hierarchy optimized state? : sql server analysis services, ssas

580


What is 2nf normalization?

533


How to create a testing table with test data in ms sql server?

548


What is an index in sql?

544


What are subquery and its properties?

569


What is similarity and difference between truncate and delete in sql?

580


How to change server name in sql server?

554


What are the main sources of data?

584