'''
Description:
The program runs and raises an exception in the grail function.
There are two classes in this program that will be used via the super() function.
Once the exception is raised, the class AlreadyGotOneToo is called, thus calling the AlreadyGotOne class.
Here the data 200 and "message" parameters are passed down to AlreadyGotOne.
So looking upward, the Exception parameter for the AlreadyGotOne is the AlreadyGotOne parameter that is a parameter
for AlreadyGotOneToo. And the 200 and message parameters are for the AlreadyGotOneToo class.
This example describes a couple important areas in python. They are nesting exceptions and using super()
'''
# User-defined exception
class AlreadyGotOne(Exception):
'''Base application exception'''
def __init__(self, statusCode, message=None):
if (message is None):
message = "An unspecified application error occured."
super(Exception, self).__init__(statusCode,message)
self.statusCode = statusCode
class AlreadyGotOneToo(AlreadyGotOne):
pass
#Raise an exception
def grail():
try:
raise AlreadyGotOneToo(200,"expression cannot be evaluated (no value found)")
print("TestPoint_grail")
except AlreadyGotOneToo as e:
print(e)
#main program
def main():
try:
grail()
except AlreadyGotOneToo: #Catch the class name
print("exception was raised")
if __name__ == "__main__":
main()