title: Catching the exception tracebacks in a loop and then raising the error(s) at the end of the script
body: <p>I'm trying to catch all exception error(s) and then at the end of the script for it to raise/show all tracebacks...</p>
  
  <p>I have a main script that calls my subscripts for example:</p>
  
  <pre><code>    errors = open('MISC/ERROR(S).txt', 'a')
  
      try:
          execfile("SUBSCRIPTS/Test1.py", {})
      except Exception:
          ## Spread over two calls of errors.write for readability in code...
          errors.write(strftime('%d/%m/%Y %H:%M:%S') + "\n")
          errors.write(traceback.format_exc() + '\n\n')
  
      try:
          execfile("SUBSCRIPTS/Test2.py", {})
      except Exception:
          ## Spread over two calls of errors.write for readability in code...
          errors.write(strftime('%d/%m/%Y %H:%M:%S') + "\n")
          errors.write(traceback.format_exc() + '\n\n')
  
      errors.close()
  </code></pre>
  
  <p>This script uses the <a href="https://docs.python.org/2/library/traceback.html" rel="nofollow">traceback</a> module to retrieve the error from the script...</p>
  
  <p>In the next example this is what my current script sort of looks like:</p>
  
  <pre><code>for x in y:
      if "example" in x:
          for tweet in tweetlist:
              # Try
              try:
                  twitter.update_status(status=tweet)
                  # Do some other stuff here if it suceeeds like...
                  print "oo example worked"
              # Damn it failed, grab the whole traceback?
              except Exception as reason:
                  FailedTweet = True
  
  # Do some other stuff here like...
  print "I did other stuff"
  
  if FailedTweet:
      print reason # Printing the reason because I don't know how to throw the exception error (full error)
  </code></pre>
  
  <p>Basically there is a big loop where it could potentially go wrong around the line: <code>twitter.update_status(status=tweet)</code> and if it does I want it to catch the traceback error(s) <strong>could be more than one because it's in a loop</strong> and then when the script finishes I want it to send all the traceback errors back to the main script so it can write them all to the error file.</p>
  
  <p>Example of the error writing to file from the first bit of code:</p>
  
  <pre><code># 17/08/2014 12:30:00
  # Traceback (most recent call last):
  #   File "C:\Main.py", line 117, in execute_subscripts
  #     execfile("SUBSCRIPTS/Test1.py", {})
  #   File "SUBSCRIPTS/Test1.py", line 440, in &lt;module&gt;
  #     twitter.update_status(status=string)
  #   File "C:\Python27\lib\site-packages\twython\endpoints.py", line 90, in update_status
  #     return self.post('statuses/update', params=params)
  #   File "C:\Python27\lib\site-packages\twython\api.py", line 234, in post
  #     return self.request(endpoint, 'POST', params=params, version=version)
  #   File "C:\Python27\lib\site-packages\twython\api.py", line 224, in request
  #     content = self._request(url, method=method, params=params, api_call=url)
  #   File "C:\Python27\lib\site-packages\twython\api.py", line 194, in _request
  #     retry_after=response.headers.get('retry-after'))
  # TwythonError: Twitter API returned a 403 (Forbidden), This request looks like it might be automated. To protect our users from spam and other malicious activity, we can't complete this action right now. Please try again later.
  </code></pre>
  
  <p><strong>How would I achieve this, it's kind of hard to explain so if something doesn't make sense please ask.</strong></p>