26.4. Explicitly Terminating SCons While Reading `SConscript` Files: the `Exit` Function
Prev | Chapter 26. Miscellaneous Functionality | Next

## 26.4. Explicitly Terminating SCons While Reading `SConscript` Files: the `Exit` Function

SCons supports an `Exit` function which can be used to terminate SCons while reading the `SConscript` files, usually because you've detected a condition under which it doesn't make sense to proceed:

    if ARGUMENTS.get('FUTURE'):
        print("The FUTURE option is not supported yet!")
        Exit(2)
    env = Environment()
    env.Program('hello.c')

    % scons -Q FUTURE=1
    The FUTURE option is not supported yet!
    % scons -Q
    cc -o hello.o -c hello.c
    cc -o hello hello.o

The `Exit` function takes as an argument the (numeric) exit status that you want SCons to exit with. If you don't specify a value, the default is to exit with `0`, which indicates successful execution.

Note that the `Exit` function is equivalent to calling the Python `sys.exit` function (which it actually calls), but because `Exit` is a SCons function, you don't have to import the Python `sys` module to use it.

Prev | Up | Next
26.3. Accessing SCons Version: the `GetSConsVersion` Function | Home | 26.5. Searching for Files: the `FindFile` Function