Skip to content

Commit

Permalink
[GR-30734] Ensure exceptions are printed before disposing of the cont…
Browse files Browse the repository at this point in the history
…ext.

PullRequest: graal/8741
  • Loading branch information
fmorcos committed Apr 15, 2021
2 parents 8782abf + c7b47e0 commit 89e4cfc
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
*
* All rights reserved.
*
Expand Down Expand Up @@ -241,27 +241,29 @@ protected static void printOption(String option, String description) {
protected int execute(Context.Builder contextBuilder) {
contextBuilder.arguments(getLanguageId(), programArgs);
try (Context context = contextBuilder.build()) {
runVersionAction(versionAction, context.getEngine());
if (toolchainAPI != null) {
printToolchainAPI(context);
return 0;
try {
runVersionAction(versionAction, context.getEngine());
if (toolchainAPI != null) {
printToolchainAPI(context);
return 0;
}
Value library = context.eval(Source.newBuilder(getLanguageId(), file).build());
if (!library.canExecute()) {
throw abort("no main function found");
}
return library.execute().asInt();
} catch (PolyglotException e) {
if (e.isExit()) {
throw e;
} else if (!e.isInternalError()) {
printStackTraceSkipTrailingHost(e);
return 1;
} else {
throw e;
}
} catch (IOException e) {
throw abort(String.format("Error loading file '%s' (%s)", file, e.getMessage()));
}
Value library = context.eval(Source.newBuilder(getLanguageId(), file).build());
if (!library.canExecute()) {
throw abort("no main function found");
}
return library.execute().asInt();
} catch (PolyglotException e) {
if (e.isExit()) {
throw e;
} else if (!e.isInternalError()) {
printStackTraceSkipTrailingHost(e);
return 1;
} else {
throw e;
}
} catch (IOException e) {
throw abort(String.format("Error loading file '%s' (%s)", file, e.getMessage()));
}
}

Expand Down

0 comments on commit 89e4cfc

Please sign in to comment.