如果要将错误作为字符串返回:>>> def test(): try: if x['error']:raise except Exception as err: return err>>> test()NameError("name 'x' is not defined",)如果要发生错误:>>> def test(): try: if x['error']:raise except: raise>>> test()Traceback (most recent call last): File "<pyshell#20>", line 1, in <module> test() File "<pyshell#19>", line 3, in test if x['error']:raiseNameError: name 'x' is not defined