1.Python 抛出异常
def test(symbol): if symbol == 1: raise Exception('can not be 1') try: test(1) except Exception as err: print(str(err))
2.Python Assert
testP = 3 assert testP >= 4, 'testP must >= 4'
3.可以用traceback.format_exc() 打印出具体的异常信息
import traceback print(traceback.format_exc())1838