Я использую следующий код
#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++
Программы на C++. Форум разработчиков
-
Anonymous
1714944204
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
Подробнее здесь: [url]https://stackoverflow.com/questions/78431736/boost-stacktrace-out-empty-source-file-and-line-num[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия