hpx/program_options/errors.hpp

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace program_options

Functions

std::string strip_prefixes(const std::string &text)
class ambiguous_option : public hpx::program_options::error_with_no_option_name
#include <errors.hpp>

Class thrown when there’s ambiguity among several possible options.

Public Functions

ambiguous_option(const std::vector<std::string> &xalternatives)
~ambiguous_option()
const std::vector<std::string> &alternatives() const

Protected Functions

void substitute_placeholders(const std::string &error_template) const

Makes all substitutions using the template

Private Members

std::vector<std::string> m_alternatives
class error : public logic_error
#include <errors.hpp>

Base class for all errors in the library.

Subclassed by hpx::program_options::duplicate_option_error, hpx::program_options::error_with_option_name, hpx::program_options::invalid_command_line_style, hpx::program_options::reading_file, hpx::program_options::too_many_positional_options_error

Public Functions

error(const std::string &xwhat)
class error_with_no_option_name : public hpx::program_options::error_with_option_name
#include <errors.hpp>

Base class of un-parsable options, when the desired option cannot be identified.

It makes no sense to have an option name, when we can’t match an option to the parameter

Having this a part of the error_with_option_name hierarchy makes error handling a lot easier, even if the name indicates some sort of conceptual dissonance!

Subclassed by hpx::program_options::ambiguous_option, hpx::program_options::unknown_option

Public Functions

error_with_no_option_name(const std::string &template_, const std::string &original_token = "")
void set_option_name(const std::string&)

Does NOT set option name, because no option name makes sense

~error_with_no_option_name()
class error_with_option_name : public hpx::program_options::error
#include <errors.hpp>

Base class for most exceptions in the library.

Substitutes the values for the parameter name placeholders in the template to create the human readable error message

Placeholders are surrounded by % signs: example% Poor man’s version of boost::format

If a parameter name is absent, perform default substitutions instead so ugly placeholders are never left in-place.

Options are displayed in “canonical” form This is the most unambiguous form of the parsed option name and would correspond to option_description::format_name() i.e. what is shown by print_usage()

The “canonical” form depends on whether the option is specified in short or long form, using dashes or slashes or without a prefix (from a configuration file)

Subclassed by hpx::program_options::error_with_no_option_name, hpx::program_options::invalid_syntax, hpx::program_options::multiple_occurrences, hpx::program_options::multiple_values, hpx::program_options::required_option, hpx::program_options::validation_error

Public Functions

error_with_option_name(const std::string &template_, const std::string &option_name = "", const std::string &original_token = "", int option_style = 0)
~error_with_option_name()

gcc says that throw specification on dtor is loosened without this line

void set_substitute(const std::string &parameter_name, const std::string &value)

Substitute parameter_name->value to create the error message from the error template

void set_substitute_default(const std::string &parameter_name, const std::string &from, const std::string &to)

If the parameter is missing, then make the from->to substitution instead

void add_context(const std::string &option_name, const std::string &original_token, int option_style)

Add context to an exception

void set_prefix(int option_style)
virtual void set_option_name(const std::string &option_name)

Overridden in error_with_no_option_name

std::string get_option_name() const
void set_original_token(const std::string &original_token)
const char *what() const

Creates the error_message on the fly Currently a thin wrapper for substitute_placeholders()

Public Members

std::string m_error_template

template with placeholders

Protected Types

using string_pair = std::pair<std::string, std::string>

Protected Functions

virtual void substitute_placeholders(const std::string &error_template) const

Makes all substitutions using the template

void replace_token(const std::string &from, const std::string &to) const
std::string get_canonical_option_name() const

Construct option name in accordance with the appropriate prefix style: i.e. long dash or short slash etc

std::string get_canonical_option_prefix() const

Protected Attributes

int m_option_style

can be 0 = no prefix (config file options) allow_long allow_dash_for_short allow_slash_for_short allow_long_disguise

std::map<std::string, std::string> m_substitutions

substitutions from placeholders to values

std::map<std::string, string_pair> m_substitution_defaults
std::string m_message

Used to hold the error text returned by what()

class invalid_bool_value : public hpx::program_options::validation_error
#include <errors.hpp>

Class thrown if there is an invalid bool value given

Public Functions

invalid_bool_value(const std::string &value)
class invalid_command_line_style : public hpx::program_options::error
#include <errors.hpp>

Class thrown when there are programming error related to style

Public Functions

invalid_command_line_style(const std::string &msg)
class invalid_command_line_syntax : public hpx::program_options::invalid_syntax
#include <errors.hpp>

Class thrown when there are syntax errors in given command line

Public Functions

invalid_command_line_syntax(kind_t kind, const std::string &option_name = "", const std::string &original_token = "", int option_style = 0)
~invalid_command_line_syntax()
class invalid_config_file_syntax : public hpx::program_options::invalid_syntax

Public Functions

invalid_config_file_syntax(const std::string &invalid_line, kind_t kind)
~invalid_config_file_syntax()
std::string tokens() const

Convenience functions for backwards compatibility

class invalid_option_value : public hpx::program_options::validation_error
#include <errors.hpp>

Class thrown if there is an invalid option value given

Public Functions

invalid_option_value(const std::string &value)
invalid_option_value(const std::wstring &value)
class invalid_syntax : public hpx::program_options::error_with_option_name
#include <errors.hpp>

Class thrown when there’s syntax error either for command line or config file options. See derived children for concrete classes.

Subclassed by hpx::program_options::invalid_command_line_syntax, hpx::program_options::invalid_config_file_syntax

Public Types

enum kind_t

Values:

long_not_allowed = 30
long_adjacent_not_allowed
short_adjacent_not_allowed
empty_adjacent_parameter
missing_parameter
extra_parameter
unrecognized_line

Public Functions

invalid_syntax(kind_t kind, const std::string &option_name = "", const std::string &original_token = "", int option_style = 0)
~invalid_syntax()
kind_t kind() const
virtual std::string tokens() const

Convenience functions for backwards compatibility

Protected Functions

std::string get_template(kind_t kind)

Used to convert kind_t to a related error text

Protected Attributes

kind_t m_kind
class multiple_occurrences : public hpx::program_options::error_with_option_name
#include <errors.hpp>

Class thrown when there are several occurrences of an option, but user called a method which cannot return them all.

Public Functions

multiple_occurrences()
~multiple_occurrences()
class multiple_values : public hpx::program_options::error_with_option_name
#include <errors.hpp>

Class thrown when there are several option values, but user called a method which cannot return them all.

Public Functions

multiple_values()
~multiple_values()
class reading_file : public hpx::program_options::error
#include <errors.hpp>

Class thrown if config file can not be read

Public Functions

reading_file(const char *filename)
class required_option : public hpx::program_options::error_with_option_name
#include <errors.hpp>

Class thrown when a required/mandatory option is missing

Public Functions

required_option(const std::string &option_name)
~required_option()
class too_many_positional_options_error : public hpx::program_options::error
#include <errors.hpp>

Class thrown when there are too many positional options. This is a programming error.

Public Functions

too_many_positional_options_error()
class unknown_option : public hpx::program_options::error_with_no_option_name
#include <errors.hpp>

Class thrown when option name is not recognized.

Public Functions

unknown_option(const std::string &original_token = "")
~unknown_option()
class validation_error : public hpx::program_options::error_with_option_name
#include <errors.hpp>

Class thrown when value of option is incorrect.

Subclassed by hpx::program_options::invalid_bool_value, hpx::program_options::invalid_option_value

Public Types

enum kind_t

Values:

multiple_values_not_allowed = 30
at_least_one_value_required
invalid_bool_value
invalid_option_value
invalid_option

Public Functions

validation_error(kind_t kind, const std::string &option_name = "", const std::string &original_token = "", int option_style = 0)
~validation_error()
kind_t kind() const

Protected Functions

std::string get_template(kind_t kind)

Used to convert kind_t to a related error text

Protected Attributes

kind_t m_kind