title: sql server passing error to application
body: <p>I need to pass the error to the application. I wrote the stored procedures as below:
  Does it pass the error to the application or we need to do the something more?</p>
  
  <p>Eg.</p>
  
  <pre><code>create procedure insert_emp 
  as
    begin try
         begin tran
           insert into emp values(..........)
         commit;
     end try
  
     begin catch
       if @@trancount &gt; 0
       rollback
       declare @errMessage varchar(2000),
       declare @errNumber int
       select @errMessage = error_message(), @errNumber = error_number()
       raiserror(@errMessage, @errNumber,1)
     end catch
  </code></pre>
  
  <p>If I need to pass 0 if there is no error and a error number if there was a error, how to do it using raiserror? How can we log the error to error_table using raiserror? More importantly can above eg. pass the error to an application?</p>