From: Erik G on
I do the following:

BEGIN TRY
exec(@execcmd)
END TRY
BEGIN CATCH
-- Execute the error retrieval routine.
print 'error'
END CATCH

and I get this:

Msg 22049, Level 16, State 1, Line 0
xp_delete_file() returned error 2, 'The system cannot find the file
specified.'
Msg 22049, Level 16, State 1, Line 0
xp_delete_file() returned error 2, 'The system cannot find the file
specified.'
Msg 22049, Level 16, State 1, Line 0
xp_delete_file() returned error 2, 'The system cannot find the file
specified.'


So I am expecting 3 lines of 'error' to be printed. Where am I going
wrong?
Thanks -Erik

From: Erland Sommarskog on
Erik G (info(a)fdaregulatory.com) writes:
> I do the following:
>
> BEGIN TRY
> exec(@execcmd)
> END TRY
> BEGIN CATCH
> -- Execute the error retrieval routine.
> print 'error'
> END CATCH
>
> and I get this:
>
> Msg 22049, Level 16, State 1, Line 0
> xp_delete_file() returned error 2, 'The system cannot find the file
> specified.'
> Msg 22049, Level 16, State 1, Line 0
> xp_delete_file() returned error 2, 'The system cannot find the file
> specified.'
> Msg 22049, Level 16, State 1, Line 0
> xp_delete_file() returned error 2, 'The system cannot find the file
> specified.'

Ah, an uncaught error! A bug in my opinion, so I submitted
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackI
D=249967

However, since this is supposedly an error with xp_delete_file (it does
not happen with xp_cmdshell) and xp_delete_file is undocumented, there
is a risk that the bug will be closed with Won't Fix.


--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx