How to raise an exception


As you create more and more complex applications you'll reach a point where you write a function, probably in a module that needs to report some error condition. You can raise an exception in a simple way.

examples/exceptions/raise.py
def some():
    raise Exception("Some Error")

def main():
    try:
        some()
    except Exception as err:
        print(err)
        print("Type: " + type(err).__name__)

main()

# Some Error
# Type: Exception