sql server - Why the procedure is not going into the catch block -
i have stored procedure selecting entry entity
table doesn't exists in our database.
in code below if execute stored procedure, it's not going catch block while every error in try block should go catch block automatically.
i not able understand reason
create procedure addupdateentity (@name varchar(20), @age smallint) begin try select name, age entity name = @name , age = @age end try begin catch select error_number() statuscode, error_message() [message] end catch go /* command execute sp */ exec addupdateentity 'sandeep',20
this execute statement showing error "invalid entity object" not calling catch block.
the stored procedure has crashed , showing message
msg 208, level 16, state 1, procedure addupdateentity, line 10
nom d'objet 'entity' non valide.
as per msdn (follow link http://msdn.microsoft.com/en-us/library/ms175976.aspx)
errors unaffected try…catch construct
try…catch constructs not trap following conditions:
warnings or informational messages have severity of 10 or lower.
errors have severity of 20 or higher stop sql server database engine task processing session. if error occurs has severity of 20 or higher , database connection not disrupted, try…catch handle error.
attentions, such client-interrupt requests or broken client connections.
when session ended system administrator using kill statement.
the following types of errors not handled catch block when occur @ same level of execution try…catch construct:
compile errors, such syntax errors, prevent batch running.
errors occur during statement-level recompilation, such object name resolution errors occur after compilation because of deferred name resolution.
these errors returned level ran batch, stored procedure, or trigger.
if error occurs during compilation or statement-level recompilation @ lower execution level (for example, when executing sp_executesql or user-defined stored procedure) inside try block, error occurs @ lower level try…catch construct , handled associated catch block.
hope above description solve problem.
Comments
Post a Comment