Programmatically stop execution of python script? [duplicate]

sys.exit() will do exactly what you want.

import sys
sys.exit("Error message")

Leave a Comment