I got a code something like this:
try: do_something() except (urllib2.URLError, socket.timeout), er: print something except Exception, ex: print "The code failed because", ex, "Please review" Now, the problem is on executing the above code I am getting following output:
The code failed because Please review p.s.: The 'ex' should return the name of the exception but its not returning anything. Any idea why?
In reference to @Yuji and @Peter, I tried this code:
try: try: print x except Exception, ex: print "ex:", ex raise except Exception, er: print "er:", er And the Output was:
ex: name 'x' is not defined . er: name 'x' is not defined . Now, why raise(er) is returning an error? And why it does not in you cases?
raise Exception?raise Exceptionprints nothing. printing the exception forraise Exception('foo')orraise Exception, 'foo'prints "foo"xis not defined, and the exception message for thatNameErroris "name 'x' is not defined". Update: theraisein the outer block is re-raising the first exception as it's supposed to