debug = System.err;
}
PrintOpts prOpts = new PrintOpts(CloudClient.getOptInPrCodes());
final Print print = new Print(prOpts, System.out, System.err, debug);
CloudMetaClient client = new CloudMetaClient(print);
ParameterProblem parameterProblem = null;
ExitNow exitNow = null;
Throwable anyError = null;
try {
mainImpl(client, argv);
} catch (ParameterProblem e) {
anyError = e;
parameterProblem = e;
} catch (ExecutionProblem e) {
anyError = e;
} catch (ExitNow e) {
exitNow = e;
} catch (Throwable e) {
anyError = e;
}
int exitCode;
if (exitNow != null) {
print.debugln("[exiting via exitnow system]");
exitCode = exitNow.exitCode;
} else if (anyError == null) {
exitCode = BaseClient.SUCCESS_EXIT_CODE;
} else {
exitCode = BaseClient.COMMAND_LINE_EXIT_CODE;
final String message =
CommonUtil.genericExceptionMessageWrapper(anyError);
String err = "Problem: " + message;
if (parameterProblem != null && !print.useLogging()) {
err += "\nSee help (-h).";
}
print.errln(err);
print.debugln("\n");
final String sectionTitle = "STACKTRACE";
CommonPrint.printDebugSection(print, sectionTitle);
anyError.printStackTrace(print.getDebugProxy());
CommonPrint.printDebugSectionEnd(print, sectionTitle);
print.debugln("\n");
print.debugln("Stacktrace was from: " + anyError.getMessage());
}
print.flush();
print.close();
System.exit(exitCode);
}