mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-08-04 02:06:29 -04:00
Rethrow ExitExceptions if we're not handling exceptions.
This commit is contained in:
parent
8769a07cee
commit
a15700d36d
@ -10,7 +10,7 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
CmdLine cmd("Command description message", ' ', "0.9", false);
|
CmdLine cmd("Command description message", ' ', "0.9", true);
|
||||||
|
|
||||||
cmd.setExceptionHandling(false);
|
cmd.setExceptionHandling(false);
|
||||||
|
|
||||||
@ -19,6 +19,9 @@ int main(int argc, char** argv)
|
|||||||
} catch (ArgException &e) { // catch any exceptions
|
} catch (ArgException &e) { // catch any exceptions
|
||||||
cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
} catch (ExitException &e) { // catch any exceptions
|
||||||
|
cerr << "Exiting on ExitException." << endl;
|
||||||
|
return e.getExitStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ class CmdLine : public CmdLineInterface
|
|||||||
* Should CmdLine handle parsing exceptions internally?
|
* Should CmdLine handle parsing exceptions internally?
|
||||||
*/
|
*/
|
||||||
bool _handleExceptions;
|
bool _handleExceptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws an exception listing the missing args.
|
* Throws an exception listing the missing args.
|
||||||
*/
|
*/
|
||||||
@ -469,7 +469,7 @@ inline void CmdLine::parse(std::vector<std::string>& args)
|
|||||||
if ( !_handleExceptions) {
|
if ( !_handleExceptions) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_output->failure(*this,e);
|
_output->failure(*this,e);
|
||||||
} catch ( ExitException &ee ) {
|
} catch ( ExitException &ee ) {
|
||||||
@ -477,6 +477,11 @@ inline void CmdLine::parse(std::vector<std::string>& args)
|
|||||||
shouldExit = true;
|
shouldExit = true;
|
||||||
}
|
}
|
||||||
} catch (ExitException &ee) {
|
} catch (ExitException &ee) {
|
||||||
|
// If we're not handling the exceptions, rethrow.
|
||||||
|
if ( !_handleExceptions) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
estat = ee.getExitStatus();
|
estat = ee.getExitStatus();
|
||||||
shouldExit = true;
|
shouldExit = true;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,8 @@ TESTS = test1.sh \
|
|||||||
test66.sh \
|
test66.sh \
|
||||||
test67.sh \
|
test67.sh \
|
||||||
test68.sh \
|
test68.sh \
|
||||||
test69.sh
|
test69.sh \
|
||||||
|
test70.sh
|
||||||
|
|
||||||
EXTRA_DIST = $(TESTS) \
|
EXTRA_DIST = $(TESTS) \
|
||||||
test1.out \
|
test1.out \
|
||||||
@ -139,6 +140,7 @@ EXTRA_DIST = $(TESTS) \
|
|||||||
test66.out \
|
test66.out \
|
||||||
test67.out \
|
test67.out \
|
||||||
test68.out \
|
test68.out \
|
||||||
test69.out
|
test69.out \
|
||||||
|
test70.out
|
||||||
|
|
||||||
CLEANFILES = tmp.out
|
CLEANFILES = tmp.out
|
||||||
|
21
tests/test70.out
Normal file
21
tests/test70.out
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
USAGE:
|
||||||
|
|
||||||
|
../examples/test18 [--] [--version] [-h]
|
||||||
|
|
||||||
|
|
||||||
|
Where:
|
||||||
|
|
||||||
|
--, --ignore_rest
|
||||||
|
Ignores the rest of the labeled arguments following this flag.
|
||||||
|
|
||||||
|
--version
|
||||||
|
Displays version information and exits.
|
||||||
|
|
||||||
|
-h, --help
|
||||||
|
Displays usage information and exits.
|
||||||
|
|
||||||
|
|
||||||
|
Command description message
|
||||||
|
|
||||||
|
Exiting on ExitException.
|
12
tests/test70.sh
Executable file
12
tests/test70.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Checks that parsing exceptions are properly
|
||||||
|
# propagated to the caller.
|
||||||
|
../examples/test18 --help > tmp.out 2>&1
|
||||||
|
|
||||||
|
if cmp -s tmp.out $srcdir/test70.out; then
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user