title: How to use tryCatch in R?
body: <pre><code>for(i in 2:num_asset){
    assetclass &lt;- ts(mydt[,i])
    tryCatch(
      {
        fit &lt;- Arima(assetclass,order = c(2,0,2))
      },
      error = function(e){
        fit &lt;- auto.arima(assetclass)
        k=i
      }
    )
    fst &lt;-as.data.frame(forecast(fit, h=52))
  }
  </code></pre>
  
  <p>I want to run code above. But It doesn't work showing message below.</p>
  
  <blockquote>
    <p>Error in forecast(fit, h = 52) : object 'fit' not found</p>
  </blockquote>
  
  <p>My intention is ...
  If there is an error in first function( <code>fit &lt;- Arima(assetclass,order = c(2,0,2))</code> ) then, I'd like to run second function(<code>fit &lt;- auto.arima(assetclass)</code>)</p>
  
  <p>How should I do?</p>