Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Home made exception hierarcy - 3

import colors as cl

def main():
    print("start")

    try:
        cl.green()
    except cl.MyError as err:
        print(err)
        print(type(err).__name__)

    try:
        cl.blue()
    except cl.MyError as err:
        print(err)
        print(type(err).__name__)

    try:
        cl.red()
    except cl.MyError as err:
        print(err)
        print(type(err).__name__)




    print("done")


main()

Output:

start
Hulk
MyGreenError
Frozen
MyBlueError
Traceback (most recent call last):
  File "hierarchy3.py", line 30, in <module>
    main()
  File "hierarchy3.py", line 19, in main
    cl.red()
  File "/home/gabor/work/slides/python/examples/exceptions/colors.py", line 18, in red
    red_alert()
NameError: name 'red_alert' is not defined