Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Error Variable Lifetime

Author  Topic 

KazMax
Starting Member

2 Posts

Posted - 2009-08-07 : 17:18:55
If I have a stored procedure which uses try/catch, when the catch executes it will obviously have the standard error variable set (@ErrorLine etc).

If I were to then call another stored procedure to capture the error details, would those error variables still have valid values?

I can obviously pass the values as parameters to the other stored procedure, however it would be easier if I could assume that the lifetime of the error variables would survive the jump to another SP.

Andrew

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-07 : 17:33:30
you could easily test this for yourself. error_line() for example will not be reported correctly

create proc yyy
AS
select error_line(), error_procedure()
GO


Create proc zzz
AS

Begin Try
select 1/0
end try

begin catch
exec yyy
end catch
GO
Go to Top of Page

KazMax
Starting Member

2 Posts

Posted - 2009-08-07 : 23:09:56


In the words of Dr Givemealife: "why didn't I think of that?"

Stupid I know, but I came across this error handling on a database which I recently gained access to in my professional life, and believe it or not when I saw this in an existing SP the above question was exactly my response! I had always been writing catch blocks to grab the error variables on entry to the catch block (which is clearly the right way of doing it, for at least the line number), and this handling thru another SP struck me as a good idea.

Okay, virtual beers are on me for asking a real dumb question. Thanks for responding.

Andrew
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-09 : 02:55:08
LOL KazMax. We're all here to help each other out. That virtual beer is almost as good as the real ones
Go to Top of Page
   

- Advertisement -