generated from Template/H563ZI-HAL-CMake-Template
优化 TerminateHandler 函数,增强异常处理逻辑并确保错误信息通过调试串口输出
All checks were successful
Build and Upload Artifact / build and upload-artifact (push) Successful in 19m55s
All checks were successful
Build and Upload Artifact / build and upload-artifact (push) Successful in 19m55s
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user