PStack  2.0
Stack trace printer for MSVC and GCC binaries
base_exception.hpp
Go to the documentation of this file.
1 // ===-- include/psystem/exception/base_exception.hpp ----- -*- C++ -*- --=== //
2 // Copyright (c) 2014 Matt Bisson. All rights reserved.
3 
18 #pragma once
19 #ifndef PSYSTEM_EXCEPTION_BASE_EXCEPTION_HPP
20 #define PSYSTEM_EXCEPTION_BASE_EXCEPTION_HPP
21 
22 #include "exception_ns.hpp"
23 
24 #include <exception>
25 #include <iosfwd>
27 
28 namespace psystem {
29 namespace exception {
30 
74  : public std::exception,
76 {
80 protected:
90  std::string file, std::string function, uint32_t line) noexcept;
91 
102  template <typename... MessageArgs>
104  std::string file,
105  std::string function,
106  uint32_t line,
107  MessageArgs&&... message) noexcept
108  : m_what(format_message(std::forward<MessageArgs>(message)...)),
109  m_function(std::move(function)),
110  m_line_number(line),
111  m_source_file(std::move(file))
112  { }
113 
114 public:
116  virtual ~base_exception() noexcept { };
117 
121 public:
130  virtual char const *what() const noexcept override;
131 
135 public:
142  std::string const& function() const noexcept;
143 
150  uint32_t line_number() const noexcept;
151 
158  std::string const& source_file() const noexcept;
159 
163 private:
185  static std::string format_message(char const *msg, ...) noexcept;
186 
190 private:
192  std::string const m_what;
193 
195  std::string const m_function;
196 
198  uint32_t const m_line_number;
199 
201  std::string const m_source_file;
202 };
203 
204 } // namespace exception
205 } // namespace psystem
206 
210 
223 std::ostream& operator<<(
224  std::ostream& out,
225  psystem::exception::base_exception const& ex) noexcept;
226 
228 
229 #endif // PSYSTEM_EXCEPTION_BASE_EXCEPTION_HPP
uint32_t const m_line_number
The line number (in m_source_file) where the exception occurred.
Definition: base_exception.hpp:198
std::string const m_function
The function where the exception occurred.
Definition: base_exception.hpp:195
Defines the psystem::not_assignable interface.
Definition: shared_handle.hpp:782
static std::string format_message(char const *msg,...) noexcept
A functional sprintf() replacement.
Definition: base_exception.cpp:77
Base exception class from which all PSystem exceptions must inherit.
Definition: base_exception.hpp:73
virtual char const * what() const noexcept override
Return a message describing the exception that occurred.
Definition: base_exception.cpp:49
#define noexcept
Replace keyword with something useful.
Definition: platform.hpp:71
Removes the ability to use an assignment operation on derived classes.
Definition: not_assignable.hpp:42
std::string const m_source_file
The source file where the exception occurred.
Definition: base_exception.hpp:201
std::string const & source_file() const noexcept
Return the name of the source file where the exception occurred.
Definition: base_exception.cpp:67
virtual ~base_exception() noexcept
Destroy the exception (supports run-time polymorphism).
Definition: base_exception.hpp:116
std::string const m_what
A message describing the exception condition.
Definition: base_exception.hpp:192
Declarations required for the psystem::exception namespace.
Contains the process examination "system" and basic frameworks.
Definition: pstack_event_handler.hpp:28
base_exception(std::string file, std::string function, uint32_t line, MessageArgs &&...message) noexcept
Construct a base_exception instance with a formatted message.
Definition: base_exception.hpp:103
base_exception(std::string file, std::string function, uint32_t line) noexcept
Construct a base_exception instance with no message.
Definition: base_exception.cpp:32
uint32_t line_number() const noexcept
Return the line on which the exception occurred.
Definition: base_exception.cpp:61
std::string const & function() const noexcept
Return the function where the exception occurred.
Definition: base_exception.cpp:55