Line data Source code
1 : // Copyright (c) 2006-2022 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 :
21 : /** \file
22 : * \brief Definitions of the advanced getopt exceptions.
23 : *
24 : * The library generates exceptions which are defined here. These are
25 : * derived from the libexcept library so we get a stack trace whenever
26 : * an exception occurs.
27 : */
28 :
29 : #include <libexcept/exception.h>
30 :
31 :
32 :
33 :
34 : namespace advgetopt
35 : {
36 :
37 :
38 :
39 : // generic logic error (something's wrong in the library)
40 : //
41 5456 : DECLARE_LOGIC_ERROR(getopt_logic_error);
42 :
43 :
44 : // generic getopt exception
45 : //
46 84 : DECLARE_MAIN_EXCEPTION(getopt_exception);
47 :
48 :
49 : // various problems
50 : //
51 : DECLARE_EXCEPTION(getopt_exception, getopt_defined_twice);
52 14 : DECLARE_EXCEPTION(getopt_exception, getopt_initialization);
53 4 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid);
54 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid_default);
55 8 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid_parameter);
56 0 : DECLARE_EXCEPTION(getopt_exception, getopt_root_filename);
57 8 : DECLARE_EXCEPTION(getopt_exception, getopt_undefined);
58 :
59 :
60 :
61 :
62 : // the process is viewed as done, exit now
63 25 : class getopt_exit
64 : : public getopt_exception
65 : {
66 : public:
67 25 : getopt_exit(std::string const & msg, int code)
68 25 : : getopt_exception(msg)
69 25 : , f_code(code)
70 : {
71 25 : }
72 :
73 25 : int code() const
74 : {
75 25 : return f_code;
76 : }
77 :
78 : private:
79 : int f_code;
80 : };
81 :
82 :
83 :
84 :
85 : } // namespace advgetopt
86 : // vim: ts=4 sw=4 et
|