Try Catch for SQLServer T-SQL
April 07, 2008
Error handling in SQL Server T-SQL scripts is not always the most graceful thing to deal with. With the release of Microsoft SQL Server 2005 you can now use TRY / CATCH statements. Here's a simple example of try / catch on sqlserver:
BEGIN TRY -- try / catch requires SQLServer 2005 -- run your code here END TRY BEGIN CATCH PRINT 'Error Number: ' + str(error_number()) PRINT 'Line Number: ' + str(error_line()) PRINT error_message() -- handle error condition END CATCH
If you want to throw an exception with SQL Server you can use the RAISERROR() function, for example:
RAISERROR('Error Message', 18, 0);
Tweet
Related Entries
- SQL Server Express 2005, Finally Installed - September 7, 2005
- I give up! Installing SQL Server 2005 Express - February 25, 2005
- Use varchar(max) instead of text in SQL Server - December 9, 2009
- Cheat Sheet for SQL Server - April 20, 2009
- DateFormat for SQL Server - December 5, 2008
Trackbacks
Trackback Address: 695/E2DA9339CFFC01FD9698F0A1490029F2
Post a Comment
Spell Checker by Foundeo
Recent Entries
- Nginx redirect www to non www domain
- HashDOS and ColdFusion
- HackMyCF Updated for APSB11-29 Security Hotfix
- Adobe eSeminar on FuseGuard
- Determining Which Cumulative Hotfixes are Installed on ColdFusion
- Adding Two Factor Authentication to ColdFusion Administrator
- ColdFusion Developer Week at Adobe.com
- Bug Loading Scripts for CFFileUpload and CFMediaPlayer


add to del.icio.us


