I have been searching online to understand the usage of Exception.__init__(self)
for user defined exceptions.
For example:
I have two user defined exceptions with one Exception.__init__(self)
and second without.
class MyFirstError(Exception):
def __init__(self, result):
Exception.__init__(self)
self.result = result
class MySecondError(Exception):
def __init__(self, result):
self.result = result
def test():
try:
raise MyFirstError("__My First Error__")
except MyFirstError as exc:
return exc.result
def test2():
try:
raise MySecondError("__ My Second Error__")
except MySecondError as exc:
return exc.result
if __name__ == "__main__":
print(test())
print(test2())
Output:
__My First Error__
__ My Second Error__
Both of them doing similar stuff. I couldn't understand the difference.