Wednesday, February 15, 2012

Error Handling problem

I have a strange behavior when executing a CLR SP:

The SP contains the following test code:

try {
int.Parse("");
}
catch (Exception ex) {
try {
command.CommandText = "raiserror (100003, 16, 1, 'parse error') with seterror";
pipe.ExecuteAndSend(command);
}
catch {
return;
}
}

Here the SQL I use to test it

decare @.e int
begin try
exec MySP
set @.e = @.@.error
print @.e
print 'phew!'
end try
begin catch
print error_message()
end catch
print 'done'

What I expect is that, since MySP throws an error, the catch block is executed and the error message is printed out.

What happens is that
@.@.error contains the correct error code 100003
the catch block does not executes
Here the output of SSMS:

Msg 100003, Level 16, State 1, Line 1
"invalid operation: parse error"
100003
phew!
done

Any Idea of why @.@.error is set but the catch block does not executes ?

just a final note: if do not use the try/catch block in the SP and let the exception be caught into the server engine, the catch block on the T-SQL is correctly executed (and it is my current solution, sigh !!!)Hi,

see this connect bug here: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=251376

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||Thanks from providing the link.
I'm skeptical they will fix it less time than a couple of years.

No comments:

Post a Comment