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>Here is an example:</p>

<pre><code>#!/usr/bin/env python 
# -*- coding: utf-8 -*-

try:
    num = 10
    while True:
        denum = int(raw_input("&gt; "))
        res = num/denum
        print str(res)

except ZeroDivisionError:  
    print "ZeroDivisionError"
    exit(0)         
except KeyboardInterrupt:
    print "\nGoodbye!"
    exit(0) 
except Exception, error:
    print "An error encoutered"
    exit(0)
</code></pre>

<p>If you try to run that program you will see that as long you provide 
input-a number it will return to you a result till the <strong>KeyboardInterrupt</strong>
exception occurs. 
But in the meantime if it happen to occur another exception(for example if you enter a letter) it will be caught by the last <strong>general exception</strong> handler unless
a <strong>ZeroDivisionError</strong> occurs, where it will be caught by the corresponding exception and not by the others. </p>

<p>A more relevant-closer approach to what you posted would be to write the above program like that:</p>

<pre><code>#!/usr/bin/env python 
# -*- coding: utf-8 -*-

try:
    num = 10
    while True:
        denum = int(raw_input("&gt; "))
        res = num/denum
        print str(res)

except KeyboardInterrupt:
    print "\nGoodbye!"
    exit(0)     
except Exception, error:
    if "division" in str(error):
        raise error
    else:
        print "Unknown error"
        exit(0)
</code></pre>

<p>Well, in this case we are catching a general exception, but this time 
we use an <strong><em>if-else</em></strong> statement to define our code behaviour!</p>

<p>So in your example I don't 
know if it would behave the same but you could give it a try.
Hope it helps!</p>

python exception-handling