Last post Jan 08, 2010 08:57 AM by elias_kuet
Jan 07, 2010 04:29 AM|elias_kuet|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 08:35 AM|jportelas|LINK
But this applies to SQL Server 2005 and upper right?
Jan 08, 2010 08:57 AM|elias_kuet|LINK
Yes, this feature is adopted in SQL SERVER 2005 and later versions.