Nested Stored Procedure Error Handling

  • One way is to use RETURN to return non sql critical errors or user defined errors and to trap both errors after proc call

    DECLARE @Result int,@ERR int
    
    EXECUTE @Result = proc1 param,param,param...
    SET @ERR = @@ERROR
    IF (@ERR > 0)
    --critical error
    ELSE
    IF @Result > 0
    --non critical / user defined error

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Thank you, something I'll add to my toolset for capturing both sets of errors.

    I suggested a similar approach to the application developer, catching the @@ERROR and using both return and raiserror, however, the java driver is not handling it as a sql exception. With further testing, it appears that it has to do with the driver not parsing the error if a result set is also returned - this therefore does not garnner us a sql exception for the java to catch and handle. We are escalating to the driver vendor, I'll post our findings on the chance that someone else encounters this in the future.

  • Can you use an OUTPUT parameter in the top proc to return either error value (@ERR or @Result in my example) and test for this.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Very possibly, I suggest they try that.

Viewing 4 posts - 1 through 5 (of 5 total)

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