LCOV - code coverage report
Current view: top level - utilities/include/mcrl2/utilities - exception.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 11 11 100.0 %
Date: 2024-04-21 03:44:01 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Jeroen van der Wulp
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : /// \file mcrl2/utilities/exception.h
      10             : /// \brief Exception classes for use in libraries and tools
      11             : 
      12             : #ifndef MCRL2_UTILITIES_EXCEPTION_H
      13             : #define MCRL2_UTILITIES_EXCEPTION_H
      14             : 
      15             : #include <cassert>
      16             : #include <iostream>
      17             : #include <sstream>
      18             : #include <stdexcept>
      19             : 
      20             : namespace mcrl2
      21             : {
      22             : 
      23             : /**
      24             :  * \brief Standard exception class for reporting runtime errors.
      25             :  **/
      26             : class runtime_error : public std::runtime_error
      27             : {
      28             : public:
      29             :   /// \brief Constructor
      30             :   /// \param[in] message the exception message
      31        8639 :   runtime_error(const std::string& message) : std::runtime_error(message)
      32        8639 :   {}
      33             : };
      34             : 
      35             : /**
      36             :  * \brief Exception class for errors raised by the command-line parser.
      37             :  **/
      38             : class command_line_error : public runtime_error
      39             : {
      40             : private:
      41             :   std::string m_msg;
      42             : 
      43             :   /// \returns A string that contains "<name>: <message>" followed by a message pointing to --help on the next line.
      44           6 :   static std::string format(const std::string& name, const std::string& message)
      45             :   {
      46           6 :     std::stringstream s;
      47             :     s << name << ": " << message << "\n"
      48           6 :       << "Try '" << name << " --help' for more information.";
      49          12 :     return s.str();
      50           6 :   }
      51             : 
      52             : public:
      53           6 :   command_line_error(const std::string& name, const std::string& message) throw()
      54           6 :     : runtime_error(format(name, message))
      55           6 :   {}
      56             : 
      57           6 :   virtual ~command_line_error() throw() {}
      58             : };
      59             : 
      60             : } // namespace mcrl2
      61             : 
      62             : #endif

Generated by: LCOV version 1.14