Path: blob/main/contrib/kyua/utils/cmdline/exceptions.hpp
48180 views
// Copyright 2010 The Kyua Authors.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12// * Neither the name of Google Inc. nor the names of its contributors13// may be used to endorse or promote products derived from this software14// without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728/// \file utils/cmdline/exceptions.hpp29/// Exception types raised by the cmdline module.3031#if !defined(UTILS_CMDLINE_EXCEPTIONS_HPP)32#define UTILS_CMDLINE_EXCEPTIONS_HPP3334#include <stdexcept>35#include <string>3637namespace utils {38namespace cmdline {394041/// Base exception for cmdline errors.42class error : public std::runtime_error {43public:44explicit error(const std::string&);45~error(void) throw();46};474849/// Generic error to describe problems caused by the user.50class usage_error : public error {51public:52explicit usage_error(const std::string&);53~usage_error(void) throw();54};555657/// Error denoting that no argument was provided to an option that required one.58class missing_option_argument_error : public usage_error {59/// Name of the option for which no required argument was specified.60std::string _option;6162public:63explicit missing_option_argument_error(const std::string&);64~missing_option_argument_error(void) throw();6566const std::string& option(void) const;67};686970/// Error denoting that the argument provided to an option is invalid.71class option_argument_value_error : public usage_error {72/// Name of the option for which the argument was invalid.73std::string _option;7475/// Raw value of the invalid user-provided argument.76std::string _argument;7778/// Reason describing why the argument is invalid.79std::string _reason;8081public:82explicit option_argument_value_error(const std::string&, const std::string&,83const std::string&);84~option_argument_value_error(void) throw();8586const std::string& option(void) const;87const std::string& argument(void) const;88};899091/// Error denoting that the user specified an unknown option.92class unknown_option_error : public usage_error {93/// Name of the option that was not known.94std::string _option;9596public:97explicit unknown_option_error(const std::string&);98~unknown_option_error(void) throw();99100const std::string& option(void) const;101};102103104} // namespace cmdline105} // namespace utils106107108#endif // !defined(UTILS_CMDLINE_EXCEPTIONS_HPP)109110111