title: Use Try Catch Block in UDFs in SQL Server
body: <p>I have following lines of code in my user-defined function :</p>
  
  <pre><code>declare @annualStr  varchar(30)
  declare @annual float
      begin try
            set @annualStr = dbo.GetXMLValues(@businessId,@id)
            set @annual = convert(float,isnull(@annualStr,'0'))
      end try
      begin catch
            set @annual = 0
      end catch
  </code></pre>
  
  <p>The value comes from <code>dbo.GetXMLValues</code> may be a <code>varchar</code> value so I need to use try catch block to convert value into <code>float</code>..</p>
  
  <p>But it throws an error saying.. it is invalid to use try catch blocks in UDF</p>
  
  <p>Why?? And what to do to convert <code>varchar</code> value to <code>float</code> when it is unknown </p>