Line data Source code
1 : // Copyright (c) 2006-2021 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 5464 : DECLARE_LOGIC_ERROR(getopt_logic_error);
42 :
43 :
44 : // generic getopt exception
45 : //
46 34 : 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_undefined);
56 :
57 :
58 :
59 :
60 : // the process is viewed as done, exit now
61 4 : class getopt_exit
62 : : public getopt_exception
63 : {
64 : public:
65 4 : getopt_exit(std::string const & msg, int code)
66 4 : : getopt_exception(msg)
67 4 : , f_code(code)
68 : {
69 4 : }
70 :
71 4 : int code() const
72 : {
73 4 : return f_code;
74 : }
75 :
76 : private:
77 : int f_code;
78 : };
79 :
80 :
81 :
82 :
83 : } // namespace advgetopt
84 : // vim: ts=4 sw=4 et
|