You can throw an exception at any time. If it is not processed, the application will stop. You do not even need to indicate which exception you are raising.
if not yourTestHere:
raise
If you want to specify a message, you can simply raise a standard exception.
from exceptions import Exception
if not yourTestHere:
raise Exception("Script failed because of bla bla bla")
source
share