catch boost::program_options::error, do print better error message and show command line options, too.
authorRoker <roker@pep-project.org>
Tue, 03 Apr 2018 11:23:34 +0200
changeset 4541b83490a9ba2
parent 441 c51ccae4f3da
child 455 c5bd9b999c8e
catch boost::program_options::error, do print better error message and show command line options, too.
server/main.cc
     1.1 --- a/server/main.cc	Tue Mar 27 15:02:12 2018 +0200
     1.2 +++ b/server/main.cc	Tue Apr 03 11:23:34 2018 +0200
     1.3 @@ -58,8 +58,15 @@
     1.4  	;
     1.5  	
     1.6  	po::variables_map vm;
     1.7 -	po::store(po::parse_command_line(argc, argv, desc), vm);
     1.8 -	po::notify(vm);
     1.9 +	
    1.10 +	try{
    1.11 +		po::store(po::parse_command_line(argc, argv, desc), vm);
    1.12 +		po::notify(vm);
    1.13 +	}catch(const po::error& e)
    1.14 +	{
    1.15 +		std::cerr << "Cannot parse command line: " << e.what() << "\n\n" << desc << std::endl;
    1.16 +		return 2;
    1.17 +	}
    1.18  	
    1.19  	if (vm.count("help"))
    1.20  	{
    1.21 @@ -112,7 +119,7 @@
    1.22  	ja.Log() << "Good bye. :-)" << std::endl;
    1.23  	JsonAdapter::global_shutdown();
    1.24  }
    1.25 -catch (std::exception const &e)
    1.26 +catch(std::exception const& e)
    1.27  {
    1.28  	std::cerr << "Exception caught in main(): \"" << e.what() << "\"" << std::endl;
    1.29  	return 1;