python自定义异常

#coding=utf-8
class MyExceptin(Exception):
    "this is user's Exception for check the length of name "
    def __init__(self, mas):
        self.mas = mas
    def __str__(self):
        return (self.mas,'error')
def Test():
    raise MyExceptin('caojiaoyue')
try:
    Test()
except MyExceptin as e:
    print(123)

  

Welcome to visit
原文地址:https://www.cnblogs.com/Nolover/p/10983530.html