python json serialization try/except
<p>I'm trying to serialize a trivial object (only attributs / values),
I have this methode in my class.</p>

<pre><code>def to_json(self,client):
    service=self._service
    path="jsonphp/"
    path+=client
    if not os.path.exists(path):
        os.makedirs(path)
    with cdd(path):
      print os.getcwd()
      path=service+".json"
      with open(path, 'w') as outfile:
        try:
          json.dump(self.__dict__, outfile)
        except:
          print "serialization failed"
</code></pre>

<p>the whole part before the try/except is to naviguate to the correct folder. It seems to work smoothly. But when I use this methode, it always print : <code>serialization failed</code> from my <code>except</code> even tho my file.json is created and the data are correctly stored in it : <code>{"_attr1": "On", "_attr2": "On", "_attr3": "Off"}</code>
I thought the <code>except</code> block was only visited if an error had occured. </p>

<p>My questions are the fallowing : is that the "normal" behaviour of <code>try/except</code> ?</p>

<p>If not, how to have information about the exception that my except is catching ?</p>

<p>Could it be an exeption from somewhere upper in the code (before I call  <code>to_json()</code>) that is catched there ?</p>