I have implemented an errorhandling scheme with SQL 7.0 where the errormessages are stored in the master..sysmessages table and referred to by errorid. These errors can be passed between procedures with use of the RAISERROR() function and the master..sysmessages.error field is equal to the @@errorid of the RAISERROR() statement. The main limitation is that you can not use system errors, you have to code for all error cases and in the event that a system error occurs you have to substitute the user defined error in its place. The reason for this is that you can not reraise most system errors and the ones you can may or may not include variable substitution, which makes reraising the error impossible.
Sample:
IF (@variable IS NULL)
BEGIN
SET @ErrorID = xxxxx
GOTO ErrorHandler
END
---------------------
INSERT INTO TABLE()
VALUES()
SELECT @ErrorID = @@error
IF @ErrorID <> 0
BEGIN
IF @ErrorID > 50001
BEGIN
GOTO ErrorHandler
END
ELSE
BEGIN
SET @ErrorID = xxxxx
GOTO ErrorHandler
END
END
---------------------
Return 0
ErrorHandler:
IF @ErrorID <> 0
BEGIN
IF @ErrorID > 50001
BEGIN
RAISERROR(@ErrorID,16,1)
RETURN
END
ELSE
BEGIN
SET @ErrorID = xxx
RAISERROR(@ErrorID,16,1)
RETURN
END
END
Hope this helps,
Ryan