Add new exception for wrapping parser construction failures
The exception is unchecked. The reasoning is that errors during parser construction should not occur, and when they do occur it is an internal error like a failed assertion.
This allows casual uses of the options parser to stay oblivious to the possibility of failures, consistent with how DuplicateOptionDeclarationException is currently [not] handled. At the same time, the dispatcher can catch the exception to fail gracefully (by printing to stdout instead of a log file) when parser construction fails for any reason.
RELNOTES: None
PiperOrigin-RevId: 151839620
diff --git a/src/test/java/com/google/devtools/common/options/OptionsTest.java b/src/test/java/com/google/devtools/common/options/OptionsTest.java
index 21a8a06..bb8e5dc 100644
--- a/src/test/java/com/google/devtools/common/options/OptionsTest.java
+++ b/src/test/java/com/google/devtools/common/options/OptionsTest.java
@@ -485,8 +485,9 @@
try {
Options.parse(K.class, NO_ARGS).getOptions();
fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage())
+ } catch (OptionsParser.ConstructionException e) {
+ assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getCause().getMessage())
.isEqualTo(
"OptionsParsingException while retrieving default for "
+ "int1: 'null' is not an int");