Raise an error and after that return a value in Python
<p>I want to raise an error and then return a value.</p>

<pre><code>raise ValueError('Max Iter Reached')
return x
</code></pre>

<p>And make both lines work.</p>

<p>Now I found this question is stupid and I decided to print an error message.</p>

<pre><code>print 'Max Iter Reached'
return x
</code></pre>

<p>It does not make sense but In case you need it. </p>

<pre><code>def your_method(self):
    ......
    try:
        raise ValueError('Max Iter Reached')
    except ValueError as e:
        return value
</code></pre>

python