Error trapping with @@Error

Last Post 11 Apr 2002 04:04 PM by Cameron_SQL. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Cameron_SQL
New Member
New Member

--
07 Apr 2002 07:49 PM
I have a stored procedure which contains a simple select statement on a table which I know doesn't exist in my Database. It compiles ok.

When I go to call the stored procedure I get the following error which is expected.

Server: Msg 208, Level 16, State 1, Procedure testproc, Line 8
Invalid object name 'testtable'.

My question I suppose is, How can I trap the fact that this error has occured if I call this stored procedure from another stored procedure.

I have tried something like this

declare @return int
exec @return = dbo.testproc

The error occurs but I can't seem to trapp it and cater for it.

Any help would be much appreciated

Cheers

Cameron
Cameron_SQL
New Member
New Member

--
11 Apr 2002 04:04 PM
Thanks for your suggestion. I'm still getting the following error that I can't trap though.
Do you see anything wrong with this? Is it impossible to trap an error produced from an object not existing?

Server: Msg 208, Level 16, State 1, Procedure tester2, Line 7
Invalid object name 'tabledoesntexist'.

When I try to execute this statement;

exec tester1 1


CREATE Procedure tester1
(
@param1 INT
)
AS
BEGIN
DECLARE @Return int
exec @Return = tester2 1
IF @Return = 0
print 'worked ok'
ELSE
PRINT 'Error Returned was ' + CONVERT(varchar, @Return)
END
GO


CREATE Procedure tester2
(
@param1 INT
)
AS
BEGIN
select * from tabledoesntexist
End
GO



Cheers

Cameron

You are not authorized to post a reply.

Acceptable Use Policy