面试题答案
一键面试class MyCustomError(Exception):
pass
class WrappedCustomError(Exception):
pass
def check_string_length(s):
if len(s) < 5:
raise MyCustomError("字符串长度小于5")
return s
def wrapper_function(s):
try:
return check_string_length(s)
except MyCustomError as e:
raise WrappedCustomError from e
if __name__ == "__main__":
try:
wrapper_function("abc")
except WrappedCustomError as e:
print("捕获到最终异常,异常链信息如下:")
raise