# getExitCode method

int getExitCode()

Resolves the final exit code by iterating over all registered ExitCodeGenerators and returning the first non-zero code.

If none returns a non-zero value, defaults to `0`. If a Throwable or Exception is thrown while calling `getExitCode`, it logs the stack trace and sets exit code to `1`.

Example:

    int exitCode = generators.getExitCode();
    exit(exitCode);

## Implementation

    int getExitCode() {
      int exitCode = 0;
      for (ExitCodeGenerator generator in _generators) {
        try {
          int value = generator.getExitCode();
          if (value != 0) {
            exitCode = value;
            break;
          }
        } on Throwable catch (th) {
          exitCode = 1;
          th.printStackTrace();
        } on Exception catch (ex) {
          exitCode = 1;
          ex.printStackTrace();
        }
      }
      return exitCode;
    }