How to handle unexpected disconnect in Uplink program?

Here is an excerpt from my main cycle. It includes a multiple attempt at sending the email, because the connection problem that caused the first crash might still affect send_error_email. The script keeps waiting 1 second and trying to send the email again until the connection problem is solved and the email is sent without problems.

import traceback
if __name__ == '__main__':
  while True:
    try:
      # check if the file exists and do something that could crash
      time.sleep(0.2)
    except Exception as e:
      while True:
        try:
          if type(e) == 'anvil._server.AnvilWrappedError':
            send_error_email(f'Error:<br>\n{repr(e)}<br>\n{e.error_obj}')
          else:
            send_error_email(f'Error:<br>\n{traceback.format_exc()}')
          break
        except:
          time.sleep(1)