I am new to sybase. After studying a bit I came to know following is the correct way to handle error/exceptions in sybase stored procedure.

CREATE PROCEDURE dbo.sp_testErrorHandling (@age varchar(20))
AS
BEGIN
DECLARE @myerr int

BEGIN TRANSACTION mytrans

DELETE FROM TestStoredProc where Name='Z'
IF @@error<>0 BEGIN SELECT @myerr=@@error GOTO failed END

DECLARE @result int
EXECUTE @result = 5/0 /* throws an exception */
IF @@error<>0 BEGIN SELECT @myerr=@@error GOTO failed END

COMMIT TRANSACTION mytrans
RETURN 0

failed:
ROLLBACK TRANSACTION mytrans
return @myerr

END
I thought, this stored procedure would return the error code correspondin to exception devision by zero. But actually it is throwing exception.
So for which of the errors/exceptions sybase would return error code without throwing exception and for which of the errors/exceptions sybase would throw an exception directly?
Please help me to undestand the behaviour.

If a stored procedure contains only select statements(one / more than one) what is best way to return error codes when some error occurs?
regards,
Anirban