Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 08, 2010 12:57 PM by elias_kuet
Jan 07, 2010 08:29 AM|LINK
Exception Handling (using Try-Catch) in SQL Statement!
Generally, we use try-catch block in frontend code behind to handle exception, even we try to catch error which occurred at SQL statement. We can easily catch/handle the error at SQL statement, it’s really very easy and good approach to handle EXCEPTION
at SQL statement (it may be in stored procedure or in trigger or in function or in view etc.)
Try-catch statement in SQL statement as bellows:
SELECT (1/0) AS DividedByZero
SELECT ERROR_NUMBER() AS ErrorCode,
ERROR_LINE() AS LineNumber,
ERROR_MESSAGE() AS ErrorMessage
Jan 08, 2010 12:35 PM|LINK
But this applies to SQL Server 2005 and upper right?
Jan 08, 2010 12:57 PM|LINK
Yes, this feature is adopted in SQL SERVER 2005 and later versions.