WARPXM v1.10.0
Loading...
Searching...
No Matches
wxexcept.h
Go to the documentation of this file.
1#pragma once
2
3// std includes
4#include <sstream>
5#include <exception>
6#include <string>
7#include <vector>
8
9
10namespace wxm
11{
16namespace lib
17{
30class Except : public std::exception
31{
32public:
37
43 Except(const std::string& str);
44
45 Except(Except&& ex) = default;
46
52 Except(const Except& ex);
53
57 ~Except() override = default;
58
64 Except& operator=(const Except& ex);
65
72 const char* what() const noexcept override;
73
80 template<typename T> Except& operator<<(const T& ex)
81 {
82 exceptStrm << ex;
83 return *this;
84 }
85
92 Except& operator<<(std::ostream& (*p)(std::ostream&) )
93 {
94 exceptStrm << p;
95 return *this;
96 }
97
103 const std::vector<std::string>& get_stack_trace() const;
104
105private:
107 std::ostringstream exceptStrm;
109 mutable std::string exceptMsg;
111 std::vector<std::string> _stack_trace;
112
113};
114
116} // namespace lib
117} // namespace wxm
118
119// Make exception class backwards compatible
121
wxm::lib::Except is the class to use for creating and throwing exceptions.
Definition: wxexcept.h:31
Except & operator=(const Except &ex)
Assigns from supplied exception object.
~Except() override=default
Deletes exception.
Except(const std::string &str)
Creates new exception with supplied message.
const std::vector< std::string > & get_stack_trace() const
This returns the stack trace.
Except(Except &&ex)=default
Except(const Except &ex)
Copies exception and backtrace from supplied exception object.
Except & operator<<(std::ostream &(*p)(std::ostream &))
Inserts iomanip element into the output message.
Definition: wxexcept.h:92
const char * what() const noexcept override
Returns error message: this is provided for compatibility with std::exception interface.
Except()
Creates a new exception object with empty message and backtrace.
Base namespace for everything not included in the global namespace.
Definition: field_source.h:8
wxm::lib::Except WxExcept
Definition: wxexcept.h:120