Back to Suggestions - program options library
program_option's exceptions should be grouped under one struct. Currently, we have, e.g.:
class validation_error : public error { ... };
Instead, it should be
class program_options_exception : public error { ... }; class validation_error : public program_options_exception { ... };
Then, for example, you could have:
try { ... } catch (exception& e) { if (dynamic_cast<program_options_exception*>(&e)) cout << "Usage: " << ...; }
to print a usage message only in the case of a program_options-generated exception.
- People/Chuck Messenger
Actually, "error" is "boost::progam_options::error" --- i.e. it's the class from which all program options exceptions are derived. Is that already what you propose?
- People/Vladimir Prus
Oh -- so you've got your own "error"? Yes, that satisfies what I wanted.
But, the symbol "error" doesn't seem wise. I had assumed (probably wrongly) that "error" was in the std namespace. (Maybe I was thinking of "exception"). Even so, the word "error" is much too common to be used in program_option's top level.
What happens when a user does "using namespace program_options;" (which is my typical way of using boost libs)?
You might counter that you can always specify program_options::error. But I feel the genericness of the name is problematical. What if a user doesn't qualify "error"? Symbols in a library's toplevel namespace should, I feel, be reasonably specific to the library's domain.
I suggest changing "error" to "program_options_error".
- People/Chuck Messenger
I somehow don't like boost::program_options::program_options_error. I'm -0 on this proposal -- whatever reviewers in general will decide, will do.
- People/Vladimir Prus