Customizing an exception

class Myexception(Exception):
    def __init__(self,message):
        self.message=message
    def __str__(self):
        return self.message
try:
    raise Myexception("我错了")
except Myexception as e:
    print(e)

 

Guess you like

Origin www.cnblogs.com/yangzhen-ahujhc/p/12304557.html