Python assert,Exception的异常信息
异常信息类型为str
try: assert 1 > 2,'except' except Exception,e: print e,type(e) try: raise Exception('except') except Exception,e: print e,type(e) ''' result except <type 'exceptions.AssertionError'> except <type 'exceptions.Exception'> '''
异常信息类型为unicode的中文
try: assert 1 > 2,u'异常' except Exception,e: pass try: raise Exception(u'异常') except Exception,e: pass
没问题…继续看下面
try: assert 1 > 2,u'异常' except Exception,e: print type(e),'e = ',e #<type 'exceptions.AssertionError'> e = try: raise Exception(u'异常') except Exception,e: print type(e),'e = ',e #UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
so使用unicode类型作为异常信息时请小心…
转载请标明出处,原文地址(http://blog.csdn.net/lis_12/article/details/53929366).
如果觉得本文对您有帮助,请点击‘顶’支持一下,您的支持是我写作最大的动力,谢谢。