你可以,但你可能不应该:
try: do_something()except: print "Caught it!"
但是,这也会捕获类似的异常,
KeyboardInterrupt而你通常不希望那样,对吗?除非你立即重新引发异常,否则请参阅docs中的以下示例:
try: f = open('myfile.txt') s = f.readline() i = int(s.strip())except IOError as (errno, strerror): print "I/O error({0}): {1}".format(errno, strerror)except ValueError: print "Could not convert data to an integer."except: print "Unexpected error:", sys.exc_info()[0] raise


