Is there a way to detect a TRY block?

  • begin try

    exec dbo.spBlah

    end try

    GO

    create proc dbo.spBlah

    as

    --

    is there any way to know?

    --(end)

    GO

    one reason why it matters is so you can write this:

    if (@flag = 1) begin

    raiserror('hello', 16, 1)

    end

    instead of this:

    if (@flag = 1) begin

    raiserror('hello', 16, 1)

    return

    end

    without having to use

    set xact_abort on

    and on a similar topic do I have to do this:

    begin catch

    if (@@trancount > 0) rollback tran

    declare @error nvarchar(2048)

    select @error = error_message()

    raiserror(@error, 16, 1)

    end catch

    because that gets old quite quickly

    raiserror(error_message(), 16, 1)

    doesn't work

  • Why don't you just write this all the time?

    if (@flag = 1) begin

    raiserror('hello', 16, 1)

    return

    end

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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