在Python中捕获通用异常,然后使用isinstance()检测特定类型的异常以便适当地处理它,这是否合理?我现在正在使用dnspython工具包,它有一系列的异常,比如超时,NXDOMAIN响应等。这些异常是dns.exception.DNSException的子类,所以我想知道捕获DNSException然后用isinstance()检查特定异常是否合理,或者说是pythonic。例如: answers = d
isinstance(SystemExit(1), Exception)的值为True,但此代码段打印"caught by bare except SystemExit(1,)"。except Exception', str(e) print 'caught by bare except', repr(sys.exc_info()[1])
我的测试环境是Python2.6
我在Python 2.7.3和Python 3.2.3中都测试过它,都没有抛出异常。比较的结果是False。在这种情况下,我可以用不同的选项配置或运行Python来抛出异常吗?ks@ks-P35-DS3P:~$ python2[GCC 4.6.3] on linux2
Type "credits" or "license" for mo