all groups > sql server programming > november 2006 >
You're in the

sql server programming

group:

Bubbling up error messages: Nested Stored Procs


Bubbling up error messages: Nested Stored Procs MarkusJNZ NO[at]SPAM gmail.com
11/1/2006 9:29:28 PM
sql server programming: Hi, I have a stored procedure which calls another stored procedure

I would like to be able to capture any errors returned by the child
procedures in the parent.

I thought I might be able to do something like this (Given two stored
procs) A and B

create procedure A
as
begin
exec B
if@@error<>0
print @@error
end

Procedure B would call the RAISERROR function and A would be able to
capture it.

Unfortunately, this does not seem to work. I could use return values
from B but was hoping for further insight.

Thanks
Markus
Re: Bubbling up error messages: Nested Stored Procs thomasroji NO[at]SPAM gmail.com
11/1/2006 10:40:42 PM

Have a look at
http://www.sommarskog.se/error-handling-II.html

Regards
Roji. P. Thomas

[quoted text, click to view]
Re: Bubbling up error messages: Nested Stored Procs Arnie Rowland
11/1/2006 11:30:24 PM
That is exactly what the RETURN value is best suited to accomplish.

See Erland's excellent articles:

Stored Procedure -Error Handling, Background
http://www.sommarskog.se/error-handling-I.html

Stored Procedure -Error Handling, Implementation
http://www.sommarskog.se/error-handling-II.html


--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

Re: Bubbling up error messages: Nested Stored Procs Scott Morris
11/2/2006 10:44:44 AM
[quoted text, click to view]

Define "does not seem to work". Works for me using the correct logic (along
with an example of incorrect logic). It may help to refer to the
documentation in BOL regarding @@ERROR and how it is set. Erland has a much
better discussion about error handling in tsql.

create procedure testa as
RAISERROR('Not allowed',11,-1) WITH SETERROR
go

create procedure testb as
declare @err int
exec testa
set @err = @@ERROR

if @err <> 0
print @err
go

create procedure testc as
exec testa
if @@ERROR <> 0
print @@ERROR
go

exec testb
exec testc
go

drop procedure testa
drop procedure testb
drop procedure testc
go

Re: Bubbling up error messages: Nested Stored Procs MarkusJNZ NO[at]SPAM gmail.com
11/2/2006 6:58:56 PM
Thanks for your help everyone
Regards
Markus
[quoted text, click to view]
AddThis Social Bookmark Button