1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//
// Copyright (c) 2006-2007, Benjamin Kaufmann
//
// This file is part of aspcud.
//
// gringo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gringo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with gringo. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef PROGRAM_OPTIONS_ERRORS_H_INCLUDED
#define PROGRAM_OPTIONS_ERRORS_H_INCLUDED
#include <stdexcept>
namespace ProgramOptions
{
//! thrown when a value has an unexpected type
class BadValue : public std::logic_error
{
public:
BadValue(const std::string& msg)
: std::logic_error(msg)
{}
~BadValue() throw () {}
std::string getOptionName() const
{
return optionName_;
}
private:
std::string optionName_;
};
//! thrown when an option has an illegal name
class BadOptionName : public std::logic_error
{
public:
BadOptionName(const std::string& name)
: std::logic_error(std::string("bad option name: ").append(name))
{}
~BadOptionName() throw () {}
};
//! thrown when more than one option in a group has the same name
class DuplicateOption : public std::logic_error
{
public:
DuplicateOption(const std::string& name, const std::string& grp)
: std::logic_error(grp + " - " + "Duplicate Option: '" + name + "'")
, name_(name)
, grpDesc_(grp)
{}
const std::string& getOptionName() const {return name_;}
const std::string& getGroupName() const {return grpDesc_;}
~DuplicateOption() throw() {}
private:
const std::string name_;
const std::string grpDesc_;
};
//! thrown when an unknown option is requested
class UnknownOption : public std::logic_error
{
public:
UnknownOption(const std::string& name)
: std::logic_error(std::string("unknown option: ").append(name))
{}
~UnknownOption() throw() {}
};
//! thrown when there's ambiguity amoung several possible options.
class AmbiguousOption : public std::logic_error
{
public:
AmbiguousOption(const std::string& optname)
: std::logic_error(std::string("ambiguous option: ").append(optname))
{}
~AmbiguousOption() throw () {}
};
//! thrown when there are several occurrences of an option in one source
class MultipleOccurences : public std::logic_error
{
public:
MultipleOccurences(const std::string& opt)
: std::logic_error(std::string("multiple occurences: ").append(opt))
{}
~MultipleOccurences() throw () {}
};
}
#endif
|