How try...catch works with nested procedures?

  • Hi,

    I have these two sprocs.

    ---------

    CREATE PROCEDURE [dbo].[InnerSproc]

    AS

    BEGIN

    RAISERROR ('ErrorMessage', -1, -1)

    END

    ---------

    CREATE PROCEDURE [dbo].[OuterSproc]

    AS

    BEGIN

    BEGIN TRY

    EXEC InnerSproc

    PRINT 0

    END TRY

    BEGIN CATCH

    PRINT -1

    END CATCH

    END

    ----------

    If I execute the outer sproc, EXEC OuterSproc, shouldn't it print -1? Why is it printing 0?

    Thanks

  • Due to your severity -1. Use something between 11 and 19 to get it work.

    For further information see BOL for RAISERROR

    Greets

    Flo

  • Use the below to get -1

    ALTER PROCEDURE [dbo].[InnerSproc]

    AS

    BEGIN

    RAISERROR ('ErrorMessage', 12, 12)

    END

    Not all errors are trapped by TR/CATCH block. Like compile errors(Syntax errors), Process terminated by KILL command, broken client connections blah blah blah

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

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