-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clarify how to return runtime errors #44
Comments
It's smarter to keep RuntimeError and ParseError siblings, so that's what I did in #45. |
Two initial thoughts:
try {
app.parse(argc, argv);
} catch (const CLI::Error &e) {
return app.exit(e);
} (I'm okay if
I'll probably push to the PR in a minute. |
That's ok. I was worried that catching CLI::Error is too grabby, because the other errors are more like programming errors (such as adding options twice), which I thought CLI11_PARSE doesn't catch purposefully. Thanks! |
The other errors cannot be thrown from |
I've made |
I noticed that main() returns an int, but parse and callback_ return void. On the other hand, there is an exit_code stored in CLI::Error, but CLI11_PARSE catches on the more specific CLI::ParseError. This raises the question how subcommands called through run_callback should return an exit code to main that is not related to parsing, and if this should even be supported by CLI11.
A straightforward approach is to use exceptions. Of course, this can be done without any support by CLI11 already. But given that most of the required code is already in there, it seems reasonable to define CLI::RuntimeError that is handled like CLI::ParseError by CLI11_PARSE, probably by catching on CLI::RuntimeError and making CLI::ParseError derive from that. Then subcommands can simply throw CLI::RuntimeError or derivatives. If this sounds like a good idea to you, I could come up with a pull request for that.
The text was updated successfully, but these errors were encountered: