Try catch.. Binding and compilation errors

Hi Guys - 

Can try catch block also handles this kind of errors?

  --Column name or number of supplied values does not match
  --Invalid object name

Testing above test cases by giving improper column definition to a table and also wrong table name to check if we can catch the errors in catch block but it is not happening.  I know it will handle logical errors like column truncation and also 1/0 kind of errors. But just checking if there any way to handle above errors as well in any way. 

T

July 27th, 2015 2:20pm

The errors you listed above can be caught on the compilation stage unless you're executing dynamic SQL.
Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 2:32pm

The errors you listed above can be caught on the compilation stage unless you're executing dy
July 27th, 2015 2:41pm

I don't think that errors that don't allow script to compile can be logged and trapped.
Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 2:51pm

I don't think that errors that don't allow script to compile can be logged an
July 27th, 2015 2:54pm

You can only trap such errors in outer scopes; not in the scope where they occur. But be sure to have SET XACT_ABORT ON, so that you don't end up with orphaned transactions.

For a rather complete horror story of error handling in SQL Server, see my three-part series, which starts here:
http://www.sommarskog.se/error_handling/Part1.html

Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 5:51pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics