What arguments does the built-in Exception class require?

做~自己de王妃 提交于 2019-12-24 03:03:22

问题


As a followup to my previous question, I was trying to create co-operative user defined exceptions that don't violate LSP.

I tried to search the PEPs and use PyCharm but I was unable to get a clear answer. I only found this PEP, but it talks about BaseException, the docs state if you want to create a user defined exception, use Exception.

What are the required arguments that should be passed to the Exception constructor without violating LSP?

class StudentValueError(Exception):
    """Base class exceptions for Student Values"""
    def __init__(self, *args):
        super().__init__(*args)


class MissingStudentValueError(StudentValueError):
    def __init__(self, expression = "", error_message = "", *args):
        super().__init__(*args)
        self.error_message = error_message 
        self.expression = expression # expression that raise the exception.

    def __str__(self):
        return "Message: {0} Parameters: {1}".format(self.error_message, self.expression)

来源:https://stackoverflow.com/questions/55213172/what-arguments-does-the-built-in-exception-class-require

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!