Увеличить stacktrace из пустого исходного файла и номера строкиC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Увеличить stacktrace из пустого исходного файла и номера строки

Сообщение Anonymous »

Я использую следующий код
#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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»