@@ -160,6 +160,8 @@ protected void validateArguments(Map<String, String> polyglotOptions) {
160160 rArguments = preprocessRScriptOptions (options );
161161 } catch (PrintHelp e ) {
162162 printHelp (OptionCategory .USER );
163+ } catch (PrintVersion e ) {
164+ RCmdOptions .printVersion ();
163165 }
164166 } else {
165167 rArguments = this .options .getArguments ();
@@ -285,7 +287,11 @@ public static RuntimeException fatal(Throwable t, String message, Object... args
285287
286288 // CheckStyle: stop system..print check
287289
288- private static String [] preprocessRScriptOptions (RCmdOptions options ) throws PrintHelp {
290+ private static String [] preprocessRScriptOptions (RCmdOptions options ) {
291+ if (options .getBoolean (RCmdOption .VERSION )) {
292+ throw new PrintVersion ();
293+ }
294+
289295 String [] arguments = options .getArguments ();
290296 int resultArgsLength = arguments .length ;
291297 int firstNonOptionArgIndex = options .getFirstNonOptionArgIndex ();
@@ -334,7 +340,15 @@ private static String[] preprocessRScriptOptions(RCmdOptions options) throws Pri
334340 }
335341
336342 @ SuppressWarnings ("serial" )
337- static class PrintHelp extends Exception {
343+ static class PrintHelp extends RuntimeException {
344+ @ Override
345+ public synchronized Throwable fillInStackTrace () {
346+ return this ;
347+ }
348+ }
349+
350+ @ SuppressWarnings ("serial" )
351+ static class PrintVersion extends RuntimeException {
338352 @ Override
339353 public synchronized Throwable fillInStackTrace () {
340354 return this ;
0 commit comments