问题
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