I used to do error checking in SQL Server by adding a check after each statement, something like this:
if @@error != 0
begin
RAISERROR 50001 'Some error message'
RETURN
end
This has obvious problems (lots of extra code, what if you miss an error message, etc...). However, SQL Server 2005 has try-catch statements!
BEGIN TRY
{ sql_statement | statement_block }
END TRY
BEGIN CATCH
{ sql_statement | statement_block }
END CATCH
[ ; ]
This is definitely a convenient thing.
No comments:
Post a Comment