class NewError(Exception): def __init__(self,message): self.msg = message def __str__(self): return self.msg try: raise NewError('自定义新异常') except NewError as e: print(e)
输出:
自定义新异常