TRY...CATCH and Print output

  • I have a SQL script that runs statements that is enclosed by TRY-CATCH construct, it is part of SQL automation, see below

    Some of my procedures return harmless output informing me of progress. I have no control over these procedures. My problem, the Try-catch construct fews this chatter as bad and kills my script. How can I change that behavior?

    Thanks,

    BEGIN TRY

    --my code

    END TRY

    BEGIN CATCH

    DECLARE @ErrorMessage NVARCHAR(4000);

    DECLARE @ErrorSeverity INT;

    DECLARE @ErrorState INT;

    SELECT

    @ErrorMessage = ERROR_MESSAGE(),

    @ErrorSeverity = ERROR_SEVERITY(),

    @ErrorState = ERROR_STATE();

    -- Use RAISERROR inside the CATCH block to return error

    -- information about the original error that caused

    -- execution to jump to the CATCH block.

    RAISERROR (@ErrorMessage, -- Message text.

    @ErrorSeverity, -- Severity.

    @ErrorState -- State.

    );

    END CATCH

  • I guess I'm not clear on what you're asking for.

    You can't change the behavior of Try...Catch. Any raiserror with a severity between 11 and 19 will cause the code to move to the Catch block. If you want messages to print, but not to do that, they need to be severity 10 or lower. Since severity 10 is "information message", that's what I use for such messages.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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