title: How to catch the error from a stored procedure? in sql
body: <p>I have a stored procedure which can return a error this example its going to return error always</p>
  
  <pre><code>create proc regresaerror
  as
  begin
   raiserror 51001 'Error al borrar los precios especiales' 
  end
  
  declare @error varchar(max)
  set @error=''
  begin try
  set @error=exec regresaerror
  end try
  begin catch
  end catch
  </code></pre>
  
  <p>I tried it (because I need insert this error in a temporary table) but that block code get this error</p>
  
  <blockquote>
    <p><em>Msg 156, Level 15, State 1, Line 4<br>
    Incorrect syntax near the keyword 'exec'.</em></p>
  </blockquote>
  
  <p>Stored procedure couldn't be updated for add a output variable</p>
  
  <p>Then how can I catch the error?</p>