优化 TerminateHandler 函数,增强异常处理逻辑并确保错误信息通过调试串口输出
All checks were successful
Build and Upload Artifact / build and upload-artifact (push) Successful in 19m55s

This commit is contained in:
2025-05-12 13:31:39 +08:00
parent a7485fca40
commit 38aaa9b8b3

View File

@@ -1,5 +1,6 @@
#include "Helper/delay_helper.h"
#include "stm32h563xx.h"
#include <string>
#include "Center/common_center.hpp"
#include "Common/serial_port.hpp"
@@ -8,8 +9,24 @@
void TerminateHandler() {
auto led = Config::kLed;
auto led = Config::kLed;
auto& debugSerialPort = CommonCenter::GetDebugSerialPort();
std::string message;
std::exception_ptr exceptionPtr = std::current_exception();
if (exceptionPtr) {
try {
std::rethrow_exception(exceptionPtr);
} catch (const std::exception& e) {
message = e.what();
} catch (...) {
message = "Unknown exception type";
}
} else {
message = "No active exception, but terminate() was called";
}
while (true) {
debugSerialPort.WriteLineBlocking("FATAL ERROR: %s", message.c_str());
led.Toggle();
DelayS(1);
}
@@ -31,6 +48,7 @@ void Setup() {
GpioSetup();
DelaySetup();
CommonSetup();
std::set_terminate(TerminateHandler);
}
extern "C" void AppStart() {