Assume that there is a database named test in the server and you want to take a backup of that database. Run the following code without specifying the path
backup database test to disk=''
You will get the following error messages
Msg 3044, Level 16, State 2, Line 1
Invalid zero-length device name. Reissue the BACKUP statement with a valid device name.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
You can however capture the error message programatically using TRY CATCH block as shown below
begin try
backup database test to disk=''
end try
begin catch
select error_message() as [error_message]
end catch
But it captures only the last error message BACKUP DATABASE is terminating abnormally
How will you capture first error message too along with second error message?