Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Deadlock Error Handling example*/
- /*You can insert this code into a stored proc*/
- BEGIN TRY
- /*Place SQL Code in here*/
- SELECT 'Test' /*Dummy code*/
- END TRY
- BEGIN CATCH
- IF (ERROR_NUMBER() = 1205)
- BEGIN
- SELECT 'Process has been deadlocked. Please check logs or Extended events for more detail'
- END
- ELSE /*If Error is not a deadlock, let's display what type of error it is*/
- BEGIN
- /*Declare variables to hold error information*/
- DECLARE @ErrorMessage NVARCHAR(max),
- @ErrorSeverity INT,
- @ErrorState INT;
- SELECT @ErrorMessage = ERROR_MESSAGE(),
- @ErrorSeverity = ERROR_SEVERITY(),
- @ErrorState = ERROR_STATE();
- /*Now let's raise the error*/
- RAISERROR( @ErrorMessage, @ErrorSeverity, @ErrorState);
- END
- END CATCH
Add Comment
Please, Sign In to add comment