# -*- coding: utf-8 -*-
"""
Created on Tue May 14 21:44:57 2019
@author: User
"""
def raisetest(obj):
if obj != 'lao lang':
raise ValueError('这是无效的值!')
print(raisetest('lang'))
运行:
runfile('D:/0python/2.2.1错误和异常.py', wdir='D:/0python')
Traceback (most recent call last):
File "<ipython-input-121-79b287a689e4>", line 1, in <module>
runfile('D:/0python/2.2.1错误和异常.py', wdir='D:/0python')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/0python/2.2.1错误和异常.py", line 12, in <module>
print(raisetest('lang'))
File "D:/0python/2.2.1错误和异常.py", line 10, in raisetest
raise ValueError('这是无效的值!')
ValueError: 这是无效的值!