Advertisement
bluebunny72

TryCatch Example

Mar 7th, 2016
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.43 KB | None | 0 0
  1. BEGIN TRAN
  2.  
  3. --SET NOCOUNT ON
  4. DECLARE @ErrorMessage NVARCHAR(4000)
  5. DECLARE @ErrorSeverity INT
  6. DECLARE @ErrorState INT
  7.  
  8. BEGIN TRY
  9.     --Do some work...
  10. END TRY
  11.  
  12. BEGIN CATCH
  13.     ROLLBACK TRAN;
  14.  
  15.     SET @ErrorMessage = 'MySp: ' + ERROR_MESSAGE();
  16.     SET @ErrorSeverity = ERROR_SEVERITY();
  17.     SET @ErrorState = ERROR_STATE();
  18.  
  19.     RAISERROR (
  20.             @ErrorMessage
  21.             ,@ErrorSeverity
  22.             ,@ErrorState
  23.             );
  24.  
  25.     RETURN;
  26. END CATCH
  27.  
  28. COMMIT TRAN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement