Return part of result if occur a except
<p>I am using python. I have a function (getAll) that call other function in a loop (getPart) and in each step the return value is updated. In some case when I call the function that is inside the loop, this fail. I need return the result in this moment.</p>

<pre><code>def getAll(m, d, v, t, s, tn, type):
  result = []
  flag = 0
  while flag == 0:
    tempResult = getPart(m, d, v)
    for i in range(0, len(tempResult)):
      result.append(tempResult[i])
    flag = tempResult[0]
  return result

print getAll(5,4,1,'ds',8,'data')
</code></pre>

<p>I need print the result partial value,  if occur a except in some step when I call tempResult in getAll</p>

<p>Wrap your method in a try, except block. You might want to raise an exception so you can respond to it too. </p>

<pre><code>def getAll(m, d, v, t, s, tn, type):
    result = []
    flag = 0
    try:
        while flag == 0:
            tempResult = getPart(m, d, v)
            for i in range(0, len(tempResult)):
              result.append(tempResult[i])
            flag = tempResult[0]
        return result
    except Exception as e:
        print e
        return result
</code></pre>

python except