problem with error handling method

  • i have a cursor with an if/else statement inside it. at the end of each if, or else i have a line:

     

    if(@@ERROR <>0)

    GOTO ErrorHandeler

     

    the ErrorHandeler function is outside just before the last End statement of the sproc. the prob is when the cursor finishes, and the program flow comes outside the cursor this method gets called. how do i prevent this??

     

    ErrorHandler:

    BEGIN

    DECLARE @ErrFormatStr varchar(255)

    RAISERROR (@ErrFormatStr, 1, -1, 'copyPermissionsError', 100001,0)

    RETURN -200

    END

    END --last end statement

  • You could put a RETURN before your ErrorHandler: Alternately always assign @@ERROR to a local variable - for Example @ReturnValue.

    Then in ErrorHandler you can test @ReturnValue

    .

     

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply