Look at the following script

********************** sp_testerror *********************

SET NOCOUNT ON

if (exists (select * from sysobjects
where name = 'testerror' and type = 'U '))
drop table testerror
go

create table testerror (LoginName varchar(20) null)
go


insert testerror (LoginName) values ('xavier')
go


create unique nonclustered index testerror1 on testerror (loginname)

go

drop proc sp_testerror
go

create proc sp_testerror @newname varchar(20)
as

DECLARE @Message varchar(255)

BEGIN TRANSACTION

insert testerror (LoginName) values (@newname)

IF (@@error != 0)
BEGIN
Select @Message = 'did not work'
Select Message = (@newname + ' ' + @Message)
ROLLBACK TRAN
RETURN
END
ELSE
BEGIN

Select @Message = 'did work'
Select Message = (@newname + ' ' + @Message)
END


COMMIT TRANSACTION
go



NOW, EXECUTE THIS,
EXEC sp_testerror 'test'

When i try to insert a duplicate , i should get a message like
'did not work test' instead of the sql error message?
What should i change in this proc to do this ?

Yog