How to catch exceptions

  • My stored proc stops running when hit error:

    SQL Server does not exist or access denied.

    Is there a way in T-SQL to post a message and the stoce continue to run till its nature end? Something like TRY{}catch() in C++ would do the job.

  • Well, unless you are trying to connect to another Server / DB in your Stored Proc, usually "SQL Server does not exist or access denied." happens from within a program that is trying to connect to the DB.

    So this means that if you are receiving the Error in your Client App, you will need to Catch the Error there.  Other wise, determine what the Error number is in your T-SQL using the @@ERROR variable and if it is that certain number for your special error, Log it or whatever you want to do.

  • This won't help now, unfortunately, but Yukon (SQL Server 2005) is suppossed to be adding TRY CATCH blocks to Transact SQL.

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

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