Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql Server ERROR handling question

Status
Not open for further replies.

s0hel

Programmer
Jul 15, 2004
8
0
0
US
declare @table table (i int not NULL, c varchar(100))

insert into @table values ('a','1')
if (@@error <> 0)
print (' caught error.. ')



output ..

Server: Msg 245, Level 16, State 1, Line 3
Syntax error converting the varchar value 'a' to a column of data type int.


As you can see, I try to catch that error, but my debug statement does not print out. the query terminates before getting there. I want to catch that error.. anyone know how? is it even possible?

If i try to insert a NULL value and try to catch the error, it prints out my debug statement fine, but I cant seem to catch that syntax error..

Thanks,

 
Syntax errors are considered terminal and cannot be catched that way.

'a' cannot fit into int data type. In other words: fix it. :)
 
I cant go ahead and just fix it. This is part of a much bigger process and I need to update another Status Table that prints out 'Sucess' or 'Failed' or 'Still running' -- Doing this from the client side is not possible, need to do this all in sql server
 
this kind of errors can not handle by SQL server can only be handle throgh client side using Try & Catch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top