LCOV - code coverage report
Current view: top level - snapwebsites - snap_exception.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 18 5.6 %
Date: 2019-12-15 17:13:15 Functions: 2 6 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Snap Websites Server -- snap exception handling
       2             : // Copyright (c) 2014-2019  Made to Order Software Corp.  All Rights Reserved
       3             : //
       4             : // https://snapwebsites.org/
       5             : // contact@m2osw.com
       6             : //
       7             : // This program is free software; you can redistribute it and/or modify
       8             : // it under the terms of the GNU General Public License as published by
       9             : // the Free Software Foundation; either version 2 of the License, or
      10             : // (at your option) any later version.
      11             : //
      12             : // This program is distributed in the hope that it will be useful,
      13             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             : // GNU General Public License for more details.
      16             : //
      17             : // You should have received a copy of the GNU General Public License
      18             : // along with this program; if not, write to the Free Software
      19             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      20             : 
      21             : 
      22             : // self
      23             : //
      24             : #include "snapwebsites/snap_exception.h"
      25             : 
      26             : 
      27             : // snapwebsites lib
      28             : //
      29             : #include "snapwebsites/log.h"
      30             : 
      31             : 
      32             : // libexcept lib
      33             : //
      34             : #include <libexcept/exception.h>
      35             : 
      36             : 
      37             : // C++ lib
      38             : //
      39             : #include <iostream>
      40             : 
      41             : 
      42             : // C lib
      43             : //
      44             : #include <execinfo.h>
      45             : #include <unistd.h>
      46             : 
      47             : 
      48             : // last include
      49             : //
      50             : #include <snapdev/poison.h>
      51             : 
      52             : 
      53             : 
      54             : 
      55             : 
      56             : namespace snap
      57             : {
      58             : 
      59             : 
      60             : /** \brief Initialize this Snap! exception.
      61             :  *
      62             :  * Initialize the base exception class. Output a stack trace to the error log.
      63             :  *
      64             :  * \param[in] what_msg  The exception message.
      65             :  *
      66             :  * \sa output_stack_trace()
      67             :  */
      68           0 : snap_exception_base::snap_exception_base(char const * what_msg)
      69             : {
      70           0 :     SNAP_LOG_ERROR("snap_exception: ")(what_msg);
      71           0 :     output_stack_trace();
      72           0 : }
      73             : 
      74             : 
      75             : /** \brief Initialize this Snap! exception.
      76             :  *
      77             :  * Initialize the base exception class. Output a stack trace to the error log.
      78             :  *
      79             :  * \param[in] what_msg  The exception message.
      80             :  *
      81             :  * \sa output_stack_trace()
      82             :  */
      83           0 : snap_exception_base::snap_exception_base(std::string const & what_msg)
      84             : {
      85           0 :     SNAP_LOG_ERROR("snap_exception: ")(what_msg);
      86           0 :     output_stack_trace();
      87           0 : }
      88             : 
      89             : 
      90             : /** \brief Initialize this Snap! exception.
      91             :  *
      92             :  * Initialize the base exception class. Output a stack trace to the error log.
      93             :  *
      94             :  * \param[in] what_msg  The exception message.
      95             :  *
      96             :  * \sa output_stack_trace()
      97             :  */
      98           0 : snap_exception_base::snap_exception_base(QString const & what_msg)
      99             : {
     100           0 :     SNAP_LOG_ERROR("snap_exception: ")(what_msg);
     101           0 :     output_stack_trace();
     102           0 : }
     103             : 
     104             : 
     105             : /** \brief Output stack trace to log as an error.
     106             :  *
     107             :  * This static method outputs the current stack as a trace to the log. If
     108             :  * compiled with DEBUG turned on, it will also output to the stderr.
     109             :  *
     110             :  * By default, the stack trace shows you a number of backtrace equal
     111             :  * to STACK_TRACE_DEPTH (which is 20 at time of writing). You may
     112             :  * specify another number to get more or less lines. Note that a
     113             :  * really large number will generally show you the entire stack since
     114             :  * a number larger than the number of function pointers on the stack
     115             :  * will return the entire stack.
     116             :  *
     117             :  * \param[in] stack_trace_depth  The number of lines to output in our stack track.
     118             :  */
     119           0 : void snap_exception_base::output_stack_trace( int const stack_trace_depth )
     120             : {
     121           0 :     libexcept::exception_base_t eb( stack_trace_depth );
     122             : 
     123           0 :     for( auto const & stack_line : eb.get_stack_trace() )
     124             :     {
     125           0 :         SNAP_LOG_ERROR("snap_exception_base(): backtrace=")( stack_line );
     126             :     }
     127           0 : }
     128             : 
     129             : 
     130           6 : } // namespace snap
     131             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13