From 38aaa9b8b3b4e0c5f78c2b0156645b67c0045400 Mon Sep 17 00:00:00 2001 From: chauyin Date: Mon, 12 May 2025 13:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20TerminateHandler=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E5=A2=9E=E5=BC=BA=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=E5=B9=B6=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E9=80=9A=E8=BF=87=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=B8=B2=E5=8F=A3=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/App/app.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Core/App/app.cpp b/Core/App/app.cpp index 4a96a09..3a0f079 100644 --- a/Core/App/app.cpp +++ b/Core/App/app.cpp @@ -1,5 +1,6 @@ #include "Helper/delay_helper.h" #include "stm32h563xx.h" +#include #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() {