try...catch Demo : Try catch « Transact SQL « SQL Server / T-SQL Tutorial






7> CREATE TABLE SomeData
8> (
9>     SomeColumn INT
10> )
11> GO
1>
2> BEGIN TRANSACTION
3>
4> BEGIN TRY
5>     --Throw an exception on insert
6>     INSERT SomeData VALUES (CONVERT(INT, 'abc'))
7> END TRY
8> BEGIN CATCH
9>     --Try to commit...
10>     COMMIT TRANSACTION
11> END CATCH
12> GO
Msg 3930, Level 16, State 1, Server J\SQLEXPRESS, Line 10
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
1>
2>
3> drop table SomeData;
4> GO








20.23.Try catch
20.23.1.Error Handling in SQL Server 2005
20.23.2.Error Handling with TRY...CATCH
20.23.3.try...catch Demo
20.23.4.Basic TRY/CATCH
20.23.5.Another TRY/CATCH
20.23.6.Nesting TRY...CATCH Calls
20.23.7.Applying TRY...CATCH Error Handling Without Recoding a Stored Procedure