This blog is moved to
http://amalhashim.wordpress.com

Wednesday, January 21, 2009

Try - Catch in Sql Server 2005

  • A TRY Block - the TRY block contains the code / script that might cause an exception

  • A CATCH Block - if an exception occurs from one of the statements in the TRY block, control is branched to the CATCH block, where the exception can be handled, logged, and so on.

BEGIN TRY

BEGIN TRANSACTION

stmts...

END TRAN

END TRY
BEGIN CATCH

IF @@TRANCOUNT > 0
ROLLBACK TRAN

END CATCH


1 comment:

Moving said...

I found your post helpful while trying to figure this out. I added a couple of statements in my CODE to show the program flow.
Thanks,