Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

Make is possible to retrieve all error messages in a CATCH handler

When you trap an error in a CATCH handler, you can use the functions error_message, error_number etc to get information about the error. This works well, as long as only one error message is produced. However, there are situations where multiple error message. In this case you can only retrieve one error message, and with a bit of bad luck this is only a generic error message. A typical example is BACKUP-RESTORE:
BEGIN TRY
BACKUP DATABASE msdb TO DISK = 'X:\nosuchdisk\dxx.bak'
END TRY
BEGIN CATCH
PRINT error_message()
END CATCH

The output is "BACKUP DATABASE is terminating abnormally." The message that path does not exist is lost.

In the long run, this is not satisfactory, and you should have a better story.

5 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    AdminMicrosoft SQL Server (Admin, Microsoft Azure) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base