How to trap SQL Server Error Messages?

  • I am having a problem at the time of calling a procedure inside another procedure. When the inner procedure causes a SQL Server Error Message Like vialation of constraints, I want to suppress the actual error message and present it in a form of my customized error message. Can any one please help me..

  • To check for an error you use @@ERROR immediately after the given statement:

    IF @@ERROR <> 0 <do something>

    To raise a custom message, you can use the RAISERROR command:

    RAISERROR( 'ERROR: bla-bla-bla', 16, -1 )

    You could also create custom error messages in sysmessages and call those by number:

    RAISERROR( 50001, 16, -1 )

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

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