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>This is not necessarily the best solution, since depending on the error, it may be better to prevent it than to handle it in this way. However, you can <a href="https://docs.python.org/3/tutorial/errors.html#handling-exceptions" rel="nofollow">try</a> (no pun originally intended...) the following (where <code>WhateverError</code> is the error that is raised in your case):</p>

<pre><code>def getAll(m, d, v, t, s, tn, type):
  result = []
  flag = 0
  while flag == 0:
    try:
      tempResult = getPart(m, d, v)
    except WhateverError:
      return result
    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>

python except