LCOV - code coverage report
Current view: top level - advgetopt - exception.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 16 100.0 %
Date: 2022-07-15 17:40:56 Functions: 19 28 67.9 %
Legend: Lines: hit not hit

          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             : // 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        5450 : DECLARE_LOGIC_ERROR(getopt_logic_error);
      44             : 
      45             : 
      46             : // generic getopt exception
      47             : //
      48         184 : DECLARE_MAIN_EXCEPTION(getopt_exception);
      49             : 
      50             : 
      51             : // various problems
      52             : //
      53           4 : DECLARE_EXCEPTION(getopt_exception, getopt_defined_twice);
      54          14 : DECLARE_EXCEPTION(getopt_exception, getopt_initialization);
      55           4 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid);
      56             : DECLARE_EXCEPTION(getopt_exception, getopt_invalid_default);
      57          88 : DECLARE_EXCEPTION(getopt_exception, getopt_invalid_parameter);
      58           4 : DECLARE_EXCEPTION(getopt_exception, getopt_root_filename);
      59          10 : DECLARE_EXCEPTION(getopt_exception, getopt_undefined);
      60             : 
      61             : 
      62             : 
      63             : 
      64             : // the process is viewed as done, exit now
      65          30 : class getopt_exit
      66             :     : public getopt_exception
      67             : {
      68             : public:
      69          30 :     getopt_exit(std::string const & msg, int code)
      70          30 :         : getopt_exception(msg)
      71          30 :         , f_code(code)
      72             :     {
      73          30 :         set_parameter("exit_code", std::to_string(code));
      74          30 :     }
      75             : 
      76          28 :     int code() const
      77             :     {
      78          28 :         return f_code;
      79             :     }
      80             : 
      81             : private:
      82             :     int             f_code;
      83             : };
      84             : 
      85             : 
      86             : 
      87             : 
      88             : } // namespace advgetopt
      89             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13