Exception Handling

  • Hi,

    How do you handle exceptions in an SQL Server pre-compiled object (e.g- trigger and stored procedure)

    Regards,

    Abhijit

  • If it's an error I know is going to terminate the batch, I'll test for it before-hand if at possible. Otherwise, I'll check @@ERROR and take appropriate action, including rolling back a transaction, if necessary.

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

  • Yeah you really have to predict what could happen and test if that condition would be met then handle your way. Otherwise it will end the process that cause the error with a built in message.

  • Keep in mind that most errors are simple trapped and reported in the @@ERROR variable, not necessarily cancelling the current procedure. YOu are free to check @@ERROR and take what ever action is appropriate.

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

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