How to throw error and exit with a custom message in python

Calling sys.exit with a string will work. The docs mention this use explicitly:

In particular, sys.exit(“some error message”) is a quick way to exit a program when an error occurs.

Leave a Comment