title: tcl8.6: what is the built-in equivalent to 'atexit()' in stdlib or 'trap "..." EXIT' in bash?
body: <p>I'm looking for a builtin or standard package that provides functionality that is similar or equivalent to stdlib's <code>atexit()</code> and bash' <code>trap "..." EXIT</code>.</p>
  
  <p>It should catch termination due to any programatic way of ending execution, including all of the following:</p>
  
  <ul>
  <li>naturally reached end of script execution</li>
  <li>explicitly invoked <code>exit</code></li>
  <li>uncaught <code>error</code></li>
  </ul>