Skip to content
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

crash with one dash #123

Open
PaltryProgrammer opened this issue Apr 10, 2023 · 3 comments
Open

crash with one dash #123

PaltryProgrammer opened this issue Apr 10, 2023 · 3 comments

Comments

@PaltryProgrammer
Copy link

please see attached GIF demonstrate crash with one dash i.e. to wit if an option is introduced w/ one dash instead of two exception is thrown . below is code executed .

#include <boost\program_options.hpp>
#include <map>
#include <string>
using namespace std;

const string option_flag = "O";
const string option_flag_description = string("an option");

const map<string , string> options__description_map = {
	{option_flag, option_flag_description},
};

int main(int argc, const char* argv[], const char* envp[])
{
	boost::program_options::variables_map vm;
	string macros;
	boost::program_options::options_description options_description("bugyCode options");
	options_description.add_options()
		(option_flag.c_str(), boost::program_options::value<string>(&macros), option_flag_description.c_str());

	boost::program_options::store(boost::program_options::parse_command_line(argc, argv, options_description), vm);
	boost::program_options::notify(vm);
	return 0;
}

crash with one dash demonstration

@mclow mclow transferred this issue from boostorg/boost Apr 10, 2023
@vprus
Copy link
Collaborator

vprus commented Apr 10, 2023

Does this problem happen if you use try/catch (and print the exceptions)?

@PaltryProgrammer
Copy link
Author

std::exception.what() prints out unrecognised option '-O' which by the way is misspelled . -Best

@vprus
Copy link
Collaborator

vprus commented Apr 10, 2023

So, it sounds like everything works as designed - the library uses exceptions to report issues, and therefore try/catch block should always be present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants