Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 try catch raiserror

Author  Topic 

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-12 : 14:32:08
Could tell me what is wrong?
I want to display a message when finding error.
Thanks
IF '08/11/2009'>=dateadd(day, datediff(day, 0, getdate()), 0)
BEGIN TRY
INSERT INTO EMPLOYEE([EMP_ID], [GRP_ID], [STR_ID], [EXP_DATE])
SELECT 'AA', '1', ACTL, '08/11/2009' from ARTS
Where NOT EXISTS (select * from EMPLOYEE_GROUP
where EMP_ID ='AA' AND GRP_ID ='1')
END TRY
ELSE
BEGIN CATCH
DECLARE @ErrorMessage varchar(55)
select @ErrorMessage='should not do it.'
RAISERROR(@ErrorMessage,11,1)
END CATCH

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-12 : 14:37:09
take that ELSE out of there
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-12 : 14:49:56
Tahnks, but can we pop up a message box?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-12 : 15:02:43
no. error is returned to the client
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-12 : 15:11:44
Is there any way to pop up a message box?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-12 : 15:19:37
in Management Studio? no.
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-12 : 15:40:36
RAISERROR(@ErrorMessage,16,127)

Where I can find error message?
I only see

Command(s) completed successfully.
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-12 : 15:42:22
I mean that I want to break the ruuning if error occuring.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-12 : 15:46:25
you need an error to occur else the catch block won't be executed.

try this

BEGIN TRY
select 1/0
END TRY

BEGIN CATCH
DECLARE @ErrorMessage varchar(55)
select @ErrorMessage='should not do it.'
RAISERROR(@ErrorMessage,11,1)
END CATCH
Go to Top of Page
   

- Advertisement -