dbTalk Databases Forums  

Cathc error number from raiserror statement

comp.databases.sybase comp.databases.sybase


Discuss Cathc error number from raiserror statement in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Subind
 
Posts: n/a

Default Cathc error number from raiserror statement - 10-15-2009 , 04:26 AM






Hi,
I have these two procs and I'm trying to catch the error number from
the proc "call_error".
But I always get 0 as the value. It may be bcoz of the "return 0" stmt
at the end of proc "throw_error" (as it executed successfully).
I cannot change the proc throw_error. So is there a way to capture the
error value from proc "call_error"?
Appreciate any help.

drop proc throw_error;
create proc throw_error
as
begin
raiserror 500000 "Oops here is the error!!!"
return 0
end

create proc call_error
as
begin
declare @rc int, @er int
exec @rc = throw_error
select @er = @@error

print "Return: %1!, Error: %2!", @rc, @er
end


exec call_error


Thanks.

Reply With Quote
  #2  
Old   
Leonid Gvirtz
 
Posts: n/a

Default Re: Cathc error number from raiserror statement - 10-16-2009 , 03:03 AM






On Oct 15, 11:26*am, Subind <subind... (AT) gmail (DOT) com> wrote:
Quote:
Hi,
I have these two procs and I'm trying to catch the error number from
the proc "call_error".
But I always get 0 as the value. It may be bcoz of the "return 0" stmt
at the end of proc "throw_error" (as it executed successfully).
I cannot change the proc throw_error. So is there a way to capture the
error value from proc "call_error"?
Appreciate any help.

drop proc throw_error;
create proc throw_error
as
begin
* * raiserror 500000 "Oops here is the error!!!"
* * return 0
end

create proc call_error
as
begin
* * declare @rc int, @er int
* * exec @rc = throw_error
* * select @er = @@error

* * print "Return: %1!, Error: %2!", @rc, @er
end

exec call_error

Thanks.
Hi Subind

Raiserror statement doesn't stop the batch execution, it just merely
displays user-defined error message and sets @@error variable. You can
verify it by adding "select @@error" after your raiserror statement.
From call_error point of view, throw_error finishes successfully, so
the behavior you have observed is expected. See this link for other
possible options: http://infocenter.sybase.com/help/to...lug/X51638.htm

Hope it helps
Leonid Gvirtz
http://www.gvirtz-consulting.com

Reply With Quote
  #3  
Old   
Subind
 
Posts: n/a

Default Re: Cathc error number from raiserror statement - 10-24-2009 , 02:07 AM



On Oct 16, 1:03*pm, Leonid Gvirtz <lgvi... (AT) yahoo (DOT) com> wrote:
Quote:
On Oct 15, 11:26*am, Subind <subind... (AT) gmail (DOT) com> wrote:





Hi,
I have these two procs and I'm trying to catch the error number from
the proc "call_error".
But I always get 0 as the value. It may be bcoz of the "return 0" stmt
at the end of proc "throw_error" (as it executed successfully).
I cannot change the proc throw_error. So is there a way to capture the
error value from proc "call_error"?
Appreciate any help.

drop proc throw_error;
create proc throw_error
as
begin
* * raiserror 500000 "Oops here is the error!!!"
* * return 0
end

create proc call_error
as
begin
* * declare @rc int, @er int
* * exec @rc = throw_error
* * select @er = @@error

* * print "Return: %1!, Error: %2!", @rc, @er
end

exec call_error

Thanks.

Hi Subind

Raiserror statement doesn't stop the batch execution, it just merely
displays user-defined error message and sets @@error variable. You can
verify it by adding "select @@error" after your raiserror statement.
From call_error point of view, throw_error finishes successfully, so
the behavior you have observed is expected. See this link for other
possible options:http://infocenter.sybase.com/help/to...center.dc32300...

Hope it helps
Leonid Gvirtzhttp://www.gvirtz-consulting.com
Thank Leonid for the prompt reply.
I realized it later after few discussions. But my requirement was such
that I had to catch the error no which is thrown by "throw error"
proc.
But later we had to scratch the idea.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.