advgetopt 2.0.47
Parse complex command line arguments and configuration files in C++.
exception.h
Go to the documentation of this file.
1// Copyright (c) 2006-2024 Made to Order Software Corp. All Rights Reserved
2//
3// https://snapwebsites.org/project/advgetopt
4// contact@m2osw.com
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this program; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#pragma once
20
29// libexcept
30//
31#include <libexcept/exception.h>
32
33
34
35
36namespace advgetopt
37{
38
39
40
41// generic logic error (something's wrong in the library)
42//
43DECLARE_LOGIC_ERROR(getopt_logic_error);
44
45
46// generic getopt exception
47//
49
50
51// various problems
52//
53DECLARE_EXCEPTION(getopt_exception, getopt_defined_twice);
54DECLARE_EXCEPTION(getopt_exception, getopt_initialization);
56DECLARE_EXCEPTION(getopt_exception, getopt_invalid_default);
57DECLARE_EXCEPTION(getopt_exception, getopt_invalid_parameter);
58DECLARE_EXCEPTION(getopt_exception, getopt_root_filename);
60
61
62
63constexpr int const CONFIGURATION_EXIT_CODE = 9;
64
65
66// the process is viewed as done, exit now
68 : public getopt_exception
69{
70public:
71 getopt_exit(std::string const & msg, int code)
72 : getopt_exception(msg)
73 , f_code(code)
74 {
75 set_parameter("exit_code", std::to_string(code));
76 }
77
78 int code() const
79 {
80 return f_code;
81 }
82
83private:
84 int f_code = 1;
85};
86
87
88
89
90} // namespace advgetopt
91// vim: ts=4 sw=4 et
getopt_exit(std::string const &msg, int code)
Definition exception.h:71
Base exception of the advgetopt class.
The advgetopt environment to parse command line options.
DECLARE_EXCEPTION(getopt_exception, getopt_defined_twice)
DECLARE_MAIN_EXCEPTION(getopt_exception)
DECLARE_LOGIC_ERROR(getopt_logic_error)
constexpr int const CONFIGURATION_EXIT_CODE
Definition exception.h:63

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.