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 to rebuild the master database?

748


What is tablix?

136


Explain the dirty pages?

753


What is the use of sign function?

754


How to rename databases in ms sql server?

814






What is difference between aggregate and analytic function?

655


What is the command used to recompile the stored procedure at run time?

775


What do you understand by sql server agent?

685


How to assign new column names in a view?

663


How many replicas are maintained for each SQL Azure database?

138


Why transaction is important?

718


Can I disable or restrict ssrs export formats (rendering formats)?

126


Can a trigger be created on a view?

734


Does an index slow down updates on indexed columns?

716


What are the ways available in sql server to execute sql statements?

775