擅长:python、mysql、java
<p>您可以尝试一个生成器函数:</p>
<pre><code>def function():
for child in parent.children.all():
try:
yield result
except Exception as e:
yield exception
</code></pre>
<p>为了清楚起见,您可以查看:
<a href="https://stackoverflow.com/questions/11366064/handle-an-exception-thrown-in-a-generator">How to handle error thrown in a generator function</a></p>