If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > How to nicely manage errors after commands in stored procs?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-11, 01:38
Musil David Musil David is offline
Registered User
 
Join Date: Sep 2006
Location: Czech Republic
Posts: 82
How to nicely manage errors after commands in stored procs?

Hello,

I would like to know how you manage errors what concerns effectivity (reading of code and good code writing). I use thes pattern:

create procedure ...
as
declare
@error int,
@status int

select .... from .....
select @error = @@error
if @error != 0 goto ERROR


update ... from ...
select @error = @@error
if @error != 0 goto ERROR

exec @status = stored_proc
select @error = @@error
if @error != 0 or @status != 0 goto ERROR


OK:
return 0

ERROR:
if @error != 0 return @error
if @status != 0 return @status

Is it good template for errors? Did you solve this any other way? Can there be more effective management of errors e.g. shorter catch... not every statement need to be managed... or on the other hand I should manage simple selects as well. Thanks for your points of view...
Reply With Quote
  #2 (permalink)  
Old 11-24-11, 05:18
Musil David Musil David is offline
Registered User
 
Join Date: Sep 2006
Location: Czech Republic
Posts: 82
No answer for 2 months... No one cares for errors management?
Reply With Quote
  #3 (permalink)  
Old 11-30-11, 04:07
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
Maybe you can try something like this for simple sp's
Code:
<insert/select/whatever>
if @@error <> 0 
begin
   raiserror @@error
   return 1
end
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On