title: How to get the last error
body: <p>I can get the last calculated value using <code>.Last.value</code></p>
  
  <pre><code>2 + 2
  ## [1] 4
  .Last.value
  ## [1] 4
  </code></pre>
  
  <p>I can access the latest warnings using <code>last.warning</code>.</p>
  
  <pre><code>warning("!!!")
  ## Warning message:
  ## !!! 
  last.warning
  ## $`!!!`
  ##  NULL
  </code></pre>
  
  <p>I can get the text of the latest error message using <code>geterrmessage()</code></p>
  
  <pre><code>stop("!!!")
  ## Error: !!!
  geterrmessage()
  ## [1] "Error: !!!\n"
  </code></pre>
  
  <p>If I know in advance that an error might be thrown I can use <code>tryCatch</code> to return the error object.</p>
  
  <pre><code>tryCatch(stop("!!!"), error = identity)
  ## &lt;simpleError in doTryCatch(return(expr), name, parentenv, handler): !!!&gt;
  </code></pre>
  
  <p>How can I retrieve the last error as an object, after it has been thrown?</p>
  
  <p>For example, if I type</p>
  
  <pre><code>stop("!!!")
  </code></pre>
  
  <p>Then I want to be able to type <code>getlasterror()</code> or similar and retrieve a <code>simpleError</code> object.</p>