keeping the continued code that will NOT fail still in try...except?
<p><a href="http://diveintopython.net/file_handling/file_objects.html#d0e14928" rel="nofollow">Dive into Python</a> -</p>

<p>This is a small snippet from <code>fileinfo.py</code> used in the book. This is opening an MP3 file and reading the last 128 bytes to fetch and later parse the metadata.</p>

<pre><code>try:                                
  fsock = open(filename, "rb", 0) 
  try:                           
    fsock.seek(-128, 2)         
    tagdata = fsock.read(128)   
  finally:                        
    fsock.close()              
  .
  .                       # process tagdata: will NEVER raise IOError though
  .
except IOError:                     
  pass
</code></pre>

<p>This can be refactored as:</p>

<pre><code>try:                                
  fsock = open(filename, "rb", 0) 
  try:                           
    fsock.seek(-128, 2)         
    tagdata = fsock.read(128)         
except IOError:                     
  pass
finally:
  fsock.close()              

.
.                       # process tagdata
.
</code></pre>

<p>I even used to have this question when I was learning <code>Java</code>. Should we just keep the logic that can actually raise an exception inside the <code>try..except</code> block or for the sake of keeping a code that does one particular job in ONE place; keep the other code that will NEVER raise an exception also within a <code>try...except</code>?</p>
