How to capture and log custom error message after RAISERROR()

  • SQL server makes it simple to capture error numbers <50000 using ERROR_NUMBER(), ERROR_MESSAGE(), etc.  However, suppose I create a custom error, for example error# 6598745, severity 12, description "The pallet move you are attempting is not allowed (palletid %u, locationid%s) because that location has not been released by QA." 
    If my stored procedure code validates against this business logic, and the pallet moves fails, I would like to capture (store in a logging table) the message details, including the message text.  Does anybody have experience capturing and logging the complete RAISERROR text, number, etc?  Thanks, David

  • DavidL - Thursday, August 30, 2018 11:02 AM

    SQL server makes it simple to capture error numbers <50000 using ERROR_NUMBER(), ERROR_MESSAGE(), etc.  However, suppose I create a custom error, for example error# 6598745, severity 12, description "The pallet move you are attempting is not allowed (palletid %u, locationid%s) because that location has not been released by QA." 
    If my stored procedure code validates against this business logic, and the pallet moves fails, I would like to capture (store in a logging table) the message details, including the message text.  Does anybody have experience capturing and logging the complete RAISERROR text, number, etc?  Thanks, David

    Same way.

  • Huh.  That was easy :Whistling:
    Since I had never seen an example of it after a day of web 'research', I assumed it was difficult.  
    Thanks.

  • Glad to help.

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

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