class MyCustomError(Exception):  
    """自定义异常类"""  
    def __init__(self, message):  
        # 调用父类（Exception）的构造函数  
        super().__init__(self, message)  
        self.message = message  
  
    def __str__(self):  
        # 返回自定义的错误信息  
        return f"MyCustomError occurred: {self.message}"  
  
# 使用自定义异常  
try:  
    raise MyCustomError("Something went wrong!")  
except MyCustomError as e:  
    print(e)
