LCOV - code coverage report
Current view: top level - advgetopt - exception.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 14 100.0 %
Date: 2019-09-16 03:06:47 Functions: 11 19 57.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * License:
       3             :  *    Copyright (c) 2006-2019  Made to Order Software Corp.  All Rights Reserved
       4             :  *
       5             :  *    https://snapwebsites.org/
       6             :  *    contact@m2osw.com
       7             :  *
       8             :  *    This program is free software; you can redistribute it and/or modify
       9             :  *    it under the terms of the GNU General Public License as published by
      10             :  *    the Free Software Foundation; either version 2 of the License, or
      11             :  *    (at your option) any later version.
      12             :  *
      13             :  *    This program is distributed in the hope that it will be useful,
      14             :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :  *    GNU General Public License for more details.
      17             :  *
      18             :  *    You should have received a copy of the GNU General Public License along
      19             :  *    with this program; if not, write to the Free Software Foundation, Inc.,
      20             :  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      21             :  *
      22             :  * Authors:
      23             :  *    Alexis Wilke   alexis@m2osw.com
      24             :  *    Doug Barbieri  doug@m2osw.com
      25             :  */
      26             : #pragma once
      27             : 
      28             : /** \file
      29             :  * \brief Definitions of the advanced getopt exceptions.
      30             :  *
      31             :  * The library generates exceptions which are defined here. These are
      32             :  * derived from the libexcept library so we get a stack trace whenever
      33             :  * an exception occurs.
      34             :  */
      35             : 
      36             : #include <libexcept/exception.h>
      37             : 
      38             : 
      39             : 
      40             : 
      41             : namespace advgetopt
      42             : {
      43             : 
      44             : 
      45             : 
      46             : // generic logic error (something's wrong in the library)
      47        2732 : class getopt_exception_logic : public libexcept::logic_exception_t
      48             : {
      49             : public:
      50        2732 :     getopt_exception_logic(std::string const & msg) : logic_exception_t(msg) {}
      51             : };
      52             : 
      53             : 
      54             : // generic getopt exception
      55         110 : class getopt_exception : public libexcept::exception_t
      56             : {
      57             : public:
      58         110 :     getopt_exception(std::string const & msg) : exception_t(msg) {}
      59             : };
      60             : 
      61             : 
      62             : // problem with a default argument
      63             : class getopt_exception_default : public getopt_exception
      64             : {
      65             : public:
      66             :     getopt_exception_default(std::string const & msg) : getopt_exception(msg) {}
      67             : };
      68             : 
      69             : 
      70             : // trying to get an undefined option
      71           4 : class getopt_exception_undefined : public getopt_exception
      72             : {
      73             : public:
      74           4 :     getopt_exception_undefined(std::string const & msg) : getopt_exception(msg) {}
      75             : };
      76             : 
      77             : 
      78             : // something wrong in the user options
      79         102 : class getopt_exception_invalid : public getopt_exception
      80             : {
      81             : public:
      82         102 :     getopt_exception_invalid(std::string const & msg) : getopt_exception(msg) {}
      83             : };
      84             : 
      85             : 
      86             : // some initialization failed at run-time
      87             : class getopt_exception_initialization : public getopt_exception                             // LCOV_EXCL_LINE
      88             : {
      89             : public:
      90             :     getopt_exception_initialization(std::string const & msg) : getopt_exception(msg) {}     // LCOV_EXCL_LINE
      91             : };
      92             : 
      93             : 
      94             : // the process is viewed as done, exit now
      95           4 : class getopt_exception_exit : public getopt_exception
      96             : {
      97             : public:
      98           4 :     getopt_exception_exit(std::string const & msg, int code)
      99             :         : getopt_exception(msg)
     100           4 :         , f_code(code)
     101             :     {
     102           4 :     }
     103             : 
     104           4 :     int code() const
     105             :     {
     106           4 :         return f_code;
     107             :     }
     108             : 
     109             : private:
     110             :     int             f_code;
     111             : };
     112             : 
     113             : 
     114             : 
     115             : 
     116             : }   // namespace advgetopt
     117             : 
     118             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12