11/*
22 * CallstackLibrary - Library creating human-readable call stacks.
33 *
4- * Copyright (C) 2023 - 2024 mhahnFr
4+ * Copyright (C) 2023 - 2025 mhahnFr
55 *
66 * This file is part of the CallstackLibrary.
77 *
2424
2525#include < cxxabi.h>
2626#include < exception>
27- #include < ostream>
2827#include < sstream>
2928#include < string>
3029#include < typeinfo>
3130
3231#include " callstack.h"
33-
3432#include " callstack_cxx_compat.hpp"
3533
3634/* *
37- * @brief The namespace all C++ classes of the CallstackLibrary can be found in.
38- *
39- * The name stands for: **l**ib**c**all**s**tack.
35+ * The namespace all C++ classes of the CallstackLibrary can be found in.
4036 */
4137namespace lcs {
4238/* *
@@ -83,8 +79,7 @@ class exception: public std::exception {
8379
8480 const char * rawName = typeid (*this ).name ();
8581 int status;
86- char * dName = abi::__cxa_demangle (rawName, LCS_NULL, LCS_NULL, &status);
87- if (dName != LCS_NULL) {
82+ if (char * dName = abi::__cxa_demangle (rawName, LCS_NULL, LCS_NULL, &status); dName != LCS_NULL) {
8883 toReturn = dName;
8984 std::free (dName);
9085 } else {
@@ -100,7 +95,7 @@ class exception: public std::exception {
10095 * @param printStacktrace whether to automatically append the stacktrace to the exception message
10196 */
10297 explicit inline exception (const bool printStacktrace = true ) LCS_NOEXCEPT
103- : std::exception(), shouldPrintStacktrace(printStacktrace) {}
98+ : shouldPrintStacktrace(printStacktrace) {}
10499
105100 /* *
106101 * @brief Constructs an exception with the given message.
@@ -111,7 +106,7 @@ class exception: public std::exception {
111106 * @param printStacktrace whether to automatically append the stacktrace
112107 */
113108 explicit inline exception (const char * message, const bool printStacktrace = true ) LCS_NOEXCEPT
114- : std::exception(), message(message), shouldPrintStacktrace(printStacktrace) {}
109+ : message(message), shouldPrintStacktrace(printStacktrace) {}
115110
116111 /* *
117112 * Constructs an exception with the given message.
@@ -120,18 +115,18 @@ class exception: public std::exception {
120115 * @param printStacktrace whether to automatically append the stacktrace
121116 */
122117 explicit inline exception (const std::string & message, const bool printStacktrace = true ) LCS_NOEXCEPT
123- : std::exception(), message(message), shouldPrintStacktrace(printStacktrace) {}
118+ : message(message), shouldPrintStacktrace(printStacktrace) {}
124119
125120 inline exception (const exception & other)
126121 : std::exception(other), message(other.message), shouldPrintStacktrace(other.shouldPrintStacktrace), cs(other.cs) {}
127122
128- inline virtual ~exception () LCS_NOEXCEPT {};
129-
123+ inline ~exception () LCS_NOEXCEPT LCS_OVERRIDE {}
124+
130125#ifdef LCS_CXX11
131126 inline exception (exception &&) = default;
132127#endif
133128
134- inline virtual const char * what () const LCS_NOEXCEPT LCS_OVERRIDE {
129+ inline const char * what () const LCS_NOEXCEPT LCS_OVERRIDE {
135130 if (!messageBuffer.empty ()) {
136131 return messageBuffer.c_str ();
137132 }
@@ -141,14 +136,14 @@ class exception: public std::exception {
141136 printStacktrace (stream, true );
142137 messageBuffer = stream.str ();
143138 } else {
144- messageBuffer = getName () + (message.empty () ? " " : ( " : \" " + message + " \" " ) );
139+ messageBuffer = getName () + (message.empty () ? " " : " : \" " + message + " \" " );
145140 }
146141 return messageBuffer.c_str ();
147142 }
148143
149144 /* *
150- * Prints the stacktrace where this exception has been constructed to the given output
151- * stream.
145+ * Prints the stacktrace where this exception has been constructed to the
146+ * given output stream.
152147 *
153148 * @param out the output stream to print to
154149 * @param printMessage whether to print the message text as well
@@ -164,7 +159,7 @@ class exception: public std::exception {
164159 << " (" << callstack_frame_getShortestNameOr (&frames[i], " << Unknown >>" ) << " ) "
165160 << (frames[i].function == LCS_NULL ? " << Unknown >>" : frames[i].function )
166161 << (frames[i].sourceFile == LCS_NULL ? " "
167- : ( " (" + std::string (callstack_frame_getShortestSourceFile (&frames[i])) + " :" + toString (frames[i].sourceLine ) + " )" ) )
162+ : " (" + std::string (callstack_frame_getShortestSourceFile (&frames[i])) + " :" + toString (frames[i].sourceLine ) + " )" )
168163 << std::endl;
169164 }
170165 }
0 commit comments