2

I have two procedures PROC_A and PROC_B.

In both procedure transaction are managed.

PROC_B throws an error by calling RAISEERROR and passes a message in certain condition

RAISERROR ('Initiator is Inactive', 16, 1, 'Approve Transaction'); 

I am executing (calling) PROC_B in PROC_A. Now I want to get the error message thrown by PROC_B in PROC_A.

How can I do that?

Shnugo
  • 66,100
  • 9
  • 53
  • 114
user3048027
  • 387
  • 1
  • 5
  • 24

1 Answers1

2

Try this:

CREATE PROCEDURE dbo.TestA
AS
BEGIN
    RAISERROR ('Initiator is Inactive', 16, 1, 'Approve Transaction'); 
END;
GO

CREATE PROCEDURE dbo.TestB
AS
BEGIN
    BEGIN TRY
    EXEC dbo.TestA;
    END TRY

    BEGIN CATCH
    SELECT ERROR_MESSAGE();
    END CATCH
END;
GO

EXEC dbo.TestB;
GO

DROP PROCEDURE dbo.TestB;
DROP PROCEDURE dbo.TestA;
Shnugo
  • 66,100
  • 9
  • 53
  • 114
  • Yes I have done it in similar way ..thanks for the reply – user3048027 Mar 17 '16 at 08:36
  • Frankly speaking I don't know how to mark as answered .. I will do that once I can figure it out.. Sorry for delay response went for lunch.. Sorry once again for not marking as answered – user3048027 Mar 17 '16 at 09:11