Python reraise/recatch exception Python reraise/recatch exception python python

Python reraise/recatch exception


What about writing 2 try...except blocks like this:

try:    try:       something    except SpecificError as ex:       if str(ex) == "some error I am expecting"          print "close softly"       else:          raise exexcept Exception as ex:   print "did not close softly"   raise ex


Only a single except clause in a try block is invoked. If you want the exception to be caught higher up then you will need to use nested try blocks.


As per python tutorial there is one and only one catched exception per one try statement. You can find pretty simple example in tutorial that will also show you how to correctly use error formatting.

Anyway why do you really need second one? Could you provide more details on this?