title: Error Handling in Sybase
body: <p>Is there a way to handle errors in <code>SYBASE</code>, such as the <code>TRY-CATCH</code> block you can use in <code>MS SQL Server</code>, <code>Oracle</code>, etc?</p>
  
  <p>I've searched the web and the only option I found was the global variable <code>@@error</code>, but it didn' work as I expected, for example, the following code:</p>
  
  <pre><code>begin tran
  
  update table1
  set name = 'new name'
  where name = 'old name'
  
  update table2
  set id = 1 
  where id = 30
  -- suppose id has a unique constraint and there's already a row with id = 1
  
  IF @@error = 0
  begin
      print 'commited'
      commit
  end
  else
  begin
      print 'rolled back'
      rollback
  end
  </code></pre>
  
  <p>The will indeed rollback somehow, because the name I've changed on table1 keeps the old value as I've tested here, but it doesn't print the messages, or execute any instructions I put after the instructions that causes the error</p>
  
  <p>Can anyone help me in this? Do you know how does Sybase error handling actually works?</p>