title: Python can you have a try statement see if two separate functions will result in failure before executing either of them?
body: <p>I'm writing a program that will get a users email, name, and age, and send them an email with their info and also save the info to an excel sheet saved on the users device. I am using openpyxl if that makes any difference</p>
  <p>If the user is not connected to the internet, the program won't send an email, but will save it to the excel sheet. And if the user has the excel sheet open, but is connected to the internet, it will send an email, but not save it to the excel sheet.</p>
  <p>I'm looking for a way to see if they will both work before executing either of them.</p>
  <p>What I currently have are two separate try statements. The first one attempts to send the email, and gives an error if it fails. The second one attempts to save the excel sheet, and gives an error if it fails.</p>
  <p>send_email() is a separate function that gets the users email and name, and sends them an email.
  wb is the workbook opened with openpyxl</p>
  <pre><code>    try:
          send_email(email, name)
      except:
          print(f'An error has occured. Please make sure you are connected to a valid network')
          
      try:
          wb.save(file)
      except:
          print('An error has occured. Make sure the file is closed')
  </code></pre>
  <p>I have tried putting one of the try statements into the other, but it still doesn't achieve the desired outcome</p>
  <pre><code>    try:
          send_email(email, name)
          try:
              wb.save(file)
          except:
              print('An error has occured. Make sure the file is closed')
      except:
          print(f'An error has occured. Please make sure you are connected to a valid network')
  </code></pre>
  <p>Doing it this way gets it to not save if the email doesn't work, but still sends the email if saving doesn't work.</p>
  <p>Any help would be greatly appreciated, thanks in advance.</p>