Try catch on Job Schedule

  • Hello everyone - quick question on how to handle an error.

    Within my Stored Procedure I have a normal TRY CATCH block that handles errors and it works fine.

    The issue I have is that it will not work when the job fails due to an authentication failure; for example, we have a Linked server and something happened - we lost access and my job failed.

    However, the try catch did not capture that since the procedure never really ran.

    Is there a way to catch something like that?

    Thank you.

    AV

  • I believe you can catch that error by wrapping the SP call within a TRY CATCH.

    If you are dealing with a linked server you can also use sys.sp_testlinkedserver to check for connectivity and then execute the SP. Of course, connectivity issues could happen between the test execution and the actual code execution.

  • It is simple and makes sense - I should've though of that 🙂

    Thank you.

    Adrian

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

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