Python - Exception Raising Exceptions

Introduction

You can raise exceptions.

To trigger an exception manually, run a raise statement.

User-triggered exceptions are caught the same way as those Python raises.

Demo

try: 
    raise IndexError                    # Trigger exception manually 
except IndexError: 
    print('got exception')

Result

If the exception is not caught, user-triggered exceptions are propagated up to the top-level default exception handler.

It will terminate the program with a standard error message:

Demo

raise IndexError

Result