(1)使用raise指定异常,抛出异常时,打印参数
def test_exception():
try:
raise ValueError("value error")
except ValueError:
raise
运行结果:
ValueError: value error
(2)子类继承ValueError异常类,抛出异常时,不打印参数
class RequestDataParseError(ValueError):
"""请求数据解析错误"""
def __init__(self): # real signature unknown
pass
def test_exception():
try:
raise RequestDataParseError
except RequestDataParseError:
raise
test_exception()
运行结果:
__main__.RequestDataParseError
(3)子类继承ValueError异常类,抛出异常时,打印参数
class ValueError(Exception):
""" Inappropriate argument value (of correct type). """
def __init__(self, *args, **kw