title: Python 3 Try/Except best practice?
body: <p>This is a question about code structure, rather than syntax. I'd like to know what is best practice and why.</p>
  <p>Imagine you've got a python programme. You've got a main class like so:</p>
  <pre><code>import my_db_manager as dbm
  
  def main_loop():
     people = dbm.read_db()
     #TODO: Write rest of programme doing something with the data from people...
      
  
  if __name__ == '__main__':
      main_loop()
  </code></pre>
  <p>Then you've got several separate .py files for managing interactions with various tables in a database. One of these .py files, <code>my_db_manager</code> looks like this:</p>
  <pre><code>def read_db():
      people = []
      db = connection_manager.get_connection()
      cursor = db.cursor()
      try:
          #Database reading statement 
          sql = 'SELECT DISTINCT(name) FROM people'
          cursor.execute(sql)
          results = cursor.fetchall()
          people = [x[0] for x in results]
      except Exception as e:
          print(f'Error: {e}')
      finally:
          return people
  </code></pre>
  <p>In the example above the function <code>read_db()</code> is called from <code>main_loop()</code> in the main class. <code>read_db()</code> contains try/except clauses to manage errors in interacting with the database. While this works fine, The try/except clauses could instead be placed in <code>main_loop()</code> when calling <code>read_db()</code>. They could equally be located in both places. What is 'best practice' when using try/except? using try/except in the <code>db_manager</code> or using it in the <code>main_loop()</code> where you're managing the programmes logic flow, or using it in both places? Bear in mind I'm giving the above specific example but I'm trying to extrapolate a general rule for applying try/except when writing python.</p>