View Single Post
  #3  
Old 06-07-2019, 12:57 PM
gregg gregg is offline
Registered User
 
Join Date: Oct 2010
Posts: 51
use try/except

sys.exit(0) causes an error, but you can raise an Exception to abort a function up to a try/except block and then do nothing with the exception.

Example:

Code:
# $language = "Python"
# $interface = "1.0"

# By having a specific exception to look for,
# other exceptions won't be ignored.
class EarlyExit(Exception):
    pass

def func2():
    crt.Dialog.MessageBox("About to exit script early", "Bye")
    raise EarlyExit()

def func1():
    func2()


def main():
    try:
        func1()
        crt.Dialog.MessageBox("Should not see this", "Wut")
    except EarlyExit:
        pass

main()
Reply With Quote