Make is possible to retrieve all error messages in a CATCH handler - by Erland Sommarskog

Status : 

 


25
0
Sign in
to vote
ID 2785302 Comments
Status Active Workarounds
Type Suggestion Repros 5
Opened 6/4/2016 3:06:11 PM
Access Restriction Public

Description

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. 
Sign in to post a comment.