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.
| Author |
Topic |
|
jooorj
Posting Yak Master
126 Posts |
Posted - 2011-04-26 : 03:55:27
|
| I have the following T-sqlDECLARE @Probs intBEGIN TRYSELECT 'This will work'BEGIN TRYSELECT * FROM #TempEND TRYBEGIN CATCHSELECT 'The second catch block'END CATCHSELECT 'And then this will now work'END TRYBEGIN CATCHSELECT 'An error has occurred at line ' +LTRIM(STR(ERROR_LINE())) +' with error ' + LTRIM(STR(ERROR_NUMBER())) + ' ' + ERROR_MESSAGE()END CATCHNow the catch does not fired why? |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-04-26 : 04:10:08
|
| Because there's no run-time error there.A missing object is a parse-time error. Parse-time errors cannot be caught by a try-catch.--Gail ShawSQL Server MVP |
 |
|
|
jooorj
Posting Yak Master
126 Posts |
Posted - 2011-04-26 : 04:21:46
|
| then how to let catch executed, what is the true solution ? |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-04-26 : 04:25:22
|
| Catch does not and cannot catch parse-time errors (object does not exist, column does not exist). It catches run-time errors. So if you have pk violations, fk violations, deadlocks, data type conversion, etc, those will be caught in a catch block.--Gail ShawSQL Server MVP |
 |
|
|
jooorj
Posting Yak Master
126 Posts |
Posted - 2011-04-26 : 04:31:34
|
| Big thanx,Now I want to list all parse-time errors? what are they ? |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-04-26 : 04:37:59
|
| Object does not existColumn does not existSyntax error.The 2nd and 3rd will be thrown before execution starts. The 1st will only be thrown when that statement is reached due to deferred name resolution.--Gail ShawSQL Server MVP |
 |
|
|
jooorj
Posting Yak Master
126 Posts |
Posted - 2011-04-26 : 04:42:50
|
| Is this a bug on SQL server (2005/2008) ? |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-04-26 : 05:00:29
|
| No.--Gail ShawSQL Server MVP |
 |
|
|
|
|
|