Line data Source code
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 : 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 : // libexcept 30 : // 31 : #include <libexcept/exception.h> 32 : 33 : 34 : 35 : 36 : namespace advgetopt 37 : { 38 : 39 : 40 : 41 : // generic logic error (something's wrong in the library) 42 : // 43 5725 : DECLARE_LOGIC_ERROR(getopt_logic_error); 44 : 45 : 46 : // generic getopt exception 47 : // 48 97 : DECLARE_MAIN_EXCEPTION(getopt_exception); 49 : 50 : 51 : // various problems 52 : // 53 3 : DECLARE_EXCEPTION(getopt_exception, getopt_defined_twice); 54 7 : DECLARE_EXCEPTION(getopt_exception, getopt_initialization); 55 6 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid); 56 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid_default); 57 44 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid_parameter); 58 2 : DECLARE_EXCEPTION(getopt_exception, getopt_root_filename); 59 5 : DECLARE_EXCEPTION(getopt_exception, getopt_undefined); 60 : 61 : 62 : 63 : constexpr int const CONFIGURATION_EXIT_CODE = 9; 64 : 65 : 66 : // the process is viewed as done, exit now 67 : class getopt_exit 68 : : public getopt_exception 69 : { 70 : public: 71 30 : getopt_exit(std::string const & msg, int code) 72 30 : : getopt_exception(msg) 73 30 : , f_code(code) 74 : { 75 30 : set_parameter("exit_code", std::to_string(code)); 76 30 : } 77 : 78 28 : int code() const 79 : { 80 28 : return f_code; 81 : } 82 : 83 : private: 84 : int f_code = 1; 85 : }; 86 : 87 : 88 : 89 : 90 : } // namespace advgetopt 91 : // vim: ts=4 sw=4 et