Reputation: 29159
The following code uses xp_cmdshell to execute bcp.exe. However, it continues to run the following code even if the command/executable failed. How to raise an exception if the execution (my special case is running sybase bcp) didn't succeeded?
declare @cmd varchar(max) = 'c:\sybase\bcp.exe ....'
begin try
exec xp_cmdshell @cmd
// .... do something if there is no error when executing @cmd
// Otherwise, STOP!
end try
begin catch
// report error
end catch
Upvotes: 0
Views: 715
Reputation: 5458
xp_cmdshell will (if the invoked program cooperates) return either a 0 if the program ended successfully or Null if not. I don't think try catch will be affected either way.
Upvotes: 0