title: SQL-Server, TSQL, TRY-CATCH block
body: <p>I'm having a problem with try/catch error-handling.
  Let's have a look on my (simple) code:</p>
  
  <pre><code>BEGIN TRY
  print 'important'
  use myDB1; -- no problem, the myDB1 is in place...
  select * from dbo.Tab1;
  use myDB2;
  --here error, the myDB2 is not there, 
  --but error handling doesn't jump into catch-block
  
  select * from dbo.Tab2;
  END TRY
  BEGIN CATCH
      print 'myDB2 is not there'
  END CATCH
  </code></pre>
  
  <p>I know, I could say: </p>
  
  <p><code>select * from myDB2.dbo.Tab2</code> without changing to myDB2, but when I need to check (for example..) if a table has an identity </p>
  
  <pre><code>(((SELECT OBJECTPROPERTY( OBJECT_ID('myDB2.dbo.'+ @TableName), 'TableHasIdentity'))= 1)
  </code></pre>
  
  <p>I must run this from myDB2, otherwise I'll get a wrong result.
  So how can I catch the error in the catch-block?</p>
  
  <p>Thanks for your help</p>
  
  <p>Purclot</p>