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)

  

posted @ 2019-06-06 10:25  Django_gege  阅读(305)  评论(0编辑  收藏  举报