C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
failure.cpp
Go to the documentation of this file.
1 #include "./failure.h"
2 
3 #include "../io/ansiescapecodes.h"
4 
5 #include <iostream>
6 
7 namespace ApplicationUtilities {
8 
20  : m_what("unspecified parsing exception")
21 {
22 }
23 
28 Failure::Failure(const std::string &what)
29  : m_what(what)
30 {
31 }
32 
37 {
38 }
39 
44 const char *Failure::what() const USE_NOTHROW
45 {
46  return m_what.c_str();
47 }
48 
52 std::ostream &operator<<(std::ostream &o, const Failure &failure)
53 {
54  using namespace std;
55  using namespace EscapeCodes;
56  return o << Phrases::Error << "Unable to parse arguments: " << TextAttribute::Reset << failure.what() << "\nSee --help for available commands."
57  << endl;
58 }
59 
60 } // namespace ApplicationUtilities
Encapsulates functions for formatted terminal output using ANSI escape codes.
virtual const char * what() const USE_NOTHROW
Returns a C-style character string describing the cause of the Failure.
Definition: failure.cpp:44
Contains currently only ArgumentParser and related classes.
#define USE_NOTHROW
Marks a function as never throwing, under no circumstances.
The Failure class is thrown by an ArgumentParser when a parsing error occurs.
Definition: failure.h:12
~Failure() USE_NOTHROW
Destroys the Failure.
Definition: failure.cpp:36
Failure()
Constructs a new Failure.
Definition: failure.cpp:19
CPP_UTILITIES_EXPORT std::ostream & operator<<(std::ostream &out, Indentation indentation)