Я использую следующий код
#include
#include
#include
// Define a custom exception type
struct CustomException : std::runtime_error {
CustomException(const std::string& msg) : std::runtime_error(msg) {}
};
// Function to throw an error with message and stack trace
void throw_err(const std::string& err_msg) {
// Capture the stack trace
boost::stacktrace::stacktrace trace;
// Formulate the error message
std::string full_msg = "Error: " + err_msg + "\n";
// Append the stack trace to the error message
full_msg += "Stack Trace:\n";
for (const auto& frame : trace) {
full_msg += " " + frame.name() + " at " + frame.source_file() + ":" + std::to_string(frame.source_line()) + "\n";
}
// Throw the custom exception with the error message
throw CustomException(full_msg);
}
int main() {
try {
throw_err("An error occurred!");
} catch (const CustomException& e) {
std::cerr
Подробнее здесь: https://stackoverflow.com/questions/784 ... d-line-num
Увеличить stacktrace из пустого исходного файла и номера строки ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Номер строки не отображается с помощью Stacktrace (не использует VS для csproj) linux
Anonymous » » в форуме C# - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Номер строки не отображается с помощью Stacktrace (не использует VS для csproj) linux
Anonymous » » в форуме C# - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-