title: How to use try, except, else correctly in Python
body: <p>So I want to know which is the right way to write try except statements. I'm new to error handling in Python.</p>
  
  <p>Option 1</p>
  
  <pre><code>try:
      itemCode = items["itemCode"]
      dbObject=db.GqlQuery("SELECT * FROM %s WHERE code=:1" % dbName,itemCode).get()
      dbObject.delete() 
  except AttributeError:
      print "There's no item with that code"
  except KeyError:
      print "Bad parameter name"
  except:
      print "Unknow error" 
  </code></pre>
  
  <p>Option 2</p>
  
  <pre><code>try:
      itemCode = items["itemCode"]
  except KeyError:
      print "Bad parameter name"
  else:    
      dbObject=db.GqlQuery("SELECT * FROM %s WHERE code=:1" % dbName,itemCode).get()
      try:    
          dbObject.delete() 
      except AttributeError:
          print "There's no item with that code"
      except:
          print "Unknow error" 
  </code></pre>
  
  <p>Option 3 
  Any other better option you can think of.</p>
  
  <p>Option 1, we see that I wrap all the code in a try block. 
  Option 2, it uses nested blocks. It raises an exception on specific line statements. </p>
  
  <p>If there's an error somewhere I will be glad to know about it.</p>