Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Location
    Czech Republic
    Posts
    82

    Unanswered: 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...

  2. #2
    Join Date
    Sep 2006
    Location
    Czech Republic
    Posts
    82
    No answer for 2 months... No one cares for errors management?

  3. #3
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •