title: Functions and try() in R
body: <p>Still struggling with R, especially with error handling:</p>
  
  <p>If I use:</p>
  
  <pre><code>result &lt;- try(sqlSave(ch,df,tablename="tblTest"))
  </code></pre>
  
  <p>I can use:</p>
  
  <pre><code>if (class(result) != "try-error")
  </code></pre>
  
  <p>to check if something went wrong. No problem.</p>
  
  <p>But if I use <code>try</code> in combination with a function it doesn't work as I expected:</p>
  
  <pre><code> result &lt;- try(ch&lt;-odbcConnect("TEST"))
  </code></pre>
  
  <p>gives "-1" for <code>result</code> and "integer" for <code>class(result)</code></p>
  
  <p>So should I use</p>
  
  <pre><code>ch&lt;-odbcConnect("TEST")
  if (ch != -1)
  </code></pre>
  
  <p>and use <code>geterrmessage()</code> for the error message?</p>