RaiseError in SP

  • Hi All,

    For error handling mechanism in SP, we can use the RAISEERROR method in the catch block of the SP to throw the system defined/custom error to the calling method and rollback the transaction. My question is that whether we have to raise the error first and then do the rollback or first rollback the transaction and then raise the error. I think the order is not going to impact anything. Am i correct?

    Sample Code is

    BEGIN CATCH

    DECLARE @ErrorMessage NVARCHAR(4000)

    DECLARE @ErrorSeverity INT

    DECLARE @ErrorState INT

    SELECT @ErrorMessage = ERROR_MESSAGE(),

    @ErrorSeverity = ERROR_SEVERITY(),

    @ErrorState = ERROR_STATE()

    RAISERROR (@ErrorMessage, -- Message text.

    @ErrorSeverity, -- Severity.

    @ErrorState -- State.

    )

    ROLLBACK TRAN T1

    END CATCH

  • NO both are different .

    Rollback then raise error, then error will not raise but vice versa will raise the rerror.

    see

    begin try

    begin tran

    select 1/0 as result

    commit

    end try

    begin catch

    rollback

    select @@ERROR as error

    --rollback

    end catch

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply