Raising exception from within except clause
<p>I'm wondering if we can do something like the following:<br>
We catch socket error and if the message is different than some value,<br>
 raise the exception forward to be caught on the next general except clause below?  </p>

<pre><code>try:
    some logic to connect to a server..   

except socket.error as se:
    if se.messsage != '123':
       raise Exception(se.message)
except exception as ex:
    log.error('write something')
</code></pre>

<p>To do this, you need a set of try-catch blocks. Once, an exception has been caught, re-throwing the exception results in it being caught at the outer level. Try if else inside the blocks or simply nest try-except block in another one like this:</p>

<pre><code>try:
    try:
        #...
    except:
        raise
except:
    pass
</code></pre>

python exception-handling