title: TryCatch in a loop - R
body: <p>my initial loop is the following: </p>
  
  <pre><code> for(iRow in seq(1,nrow(df),1)){
  
  
  valueTMP &lt;- df$Set_C[iRow]
  strikeTMP &lt;- df$`Exercise price`[iRow]
  underlyingTMP &lt;- df$Compens.[iRow]
  dividendyieldTMP &lt;- df$RFR[iRow]
  riskfreerateTMP &lt;- df$RFR[iRow]
  maturityTMP &lt;- df$maturity[iRow]
  
  
    df$IV[iRow] &lt;- AmericanOptionImpliedVolatility("call", valueTMP, underlyingTMP, strikeTMP,dividendyieldTMP, riskfreerateTMP, maturityTMP, 0.4)
  
    }
  </code></pre>
  
  <p>This loop returns a value up to a certain row. I want to use <code>TryCatch</code> with it so I tried the following. However, it does not change anything to the previous result. I think something is missing in the code, that would make it return something even after error messages. </p>
  
  <pre><code>for(iRow in seq(1,nrow(df),1)){
  
  
   valueTMP &lt;- df$Set_C[iRow]
   strikeTMP &lt;- df$`Exercise price`[iRow]
   underlyingTMP &lt;- df$Compens.[iRow]
   dividendyieldTMP &lt;- df$RFR[iRow]
   riskfreerateTMP &lt;- df$RFR[iRow]
   maturityTMP &lt;- df$maturity[iRow]
  
  
  #ERROR HANDLING
  possibleError &lt;- tryCatch(
    thing(),
    error=function(e) e
  )
  
      if(inherits(possibleError, "error")) next
    df$IV[iRow] &lt;- AmericanOptionImpliedVolatility("call", valueTMP, 
  underlyingTMP, strikeTMP, dividendyieldTMP, riskfreerateTMP, maturityTMP, 0.4)
  
    }
  </code></pre>
  
  <p>Does anyone know how to make it work until the last observation, even though for some rows it won't run?
  Thanks a lot in advance. </p>