Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:31:30+00:00 2026-06-14T12:31:30+00:00

Have been integrating this (version 1.52.0) into my app, but have stumbled upon the

  • 0

Have been integrating this (version 1.52.0) into my app, but have stumbled upon the problem as described above.

In the example attached the exception what() method always still has the %canonical_option% tag intact and is not replaced with my option name.

I’m using VS2008, have disabled unicode (option ‘none’) and removed all other files from my project, it’s only this code in a main.cpp file.

Or have I got this all wrong and there is something else I should be calling to format the exception message with the correct parameter name?

#include <boost/program_options.hpp>

namespace po = boost::program_options;

using namespace std;

int main(int argc, char* argv[])
{

    try {

        po::options_description optionalParams("optional");

        optionalParams.add_options() 
            ("log_severity,l", po::value<int>()->required(), "Minimum severity logging level")
            ("log_file,g", po::value<string>(), "Full path to log file")
            ;

        po::variables_map optMap;

        po::parsed_options parsed = po::command_line_parser(argc, argv)
            .options(optionalParams)
            .allow_unregistered()
            .run();

        po::store(parsed, optMap);

        po::notify(optMap);

    }
    catch(po::error e)
    {
        cout << e.what();
        return 0;
    }

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:31:32+00:00Added an answer on June 14, 2026 at 12:31 pm

    When I look at the code again, after having a proper browse through the boost code, the answer becomes more obvious.

    catch(po::error e)
    {
        cout << e.what();
        return 0;
    }
    

    Should be

    catch(po::error& e)
    {
        cout << e.what();
        return 0;
    }
    

    Without the reference, we get ‘object slicing’ which is explained well here:

    Catching exceptions by reference

    Not using the reference means we lose the overridden ‘what’ method which does the template replacement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking into integrating testing into my app based on RequireJS. I
I might be missing something, but I have been struggling with this problem for
I have been tasked with integrating image acquisition into a .NET application and I
I have been having this issue in iterating through an array of keys and
I have been busy integrating Wordpress to one of a CakePHP application.Last Monday I
Have been working on this question for a couple hours and have come close
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been upgrading several different VS2008 projects into VS2010 and have found a
I have a solution with reference to Telerik assemblies. The referenced version has been
I have been trying to work on integrating a NewsLetter for a companies local

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.