From 3a6f660619cda46435ea5896c466b7efd10911c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=88=90?= <1741964788@qq.com> Date: Fri, 14 Apr 2023 15:10:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EAssert=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=9B=BD=E6=A0=87?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=8E=A8=E6=B5=81=E4=B8=8D=E6=B3=A8=E9=94=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#2393)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: wangcheng Co-authored-by: xia-chu <771730766@qq.com> --- src/Common/macros.cpp | 2 +- src/Common/macros.h | 7 +++++++ src/Rtp/PSDecoder.cpp | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Common/macros.cpp b/src/Common/macros.cpp index 26c4ab80..378c6ba1 100644 --- a/src/Common/macros.cpp +++ b/src/Common/macros.cpp @@ -26,7 +26,7 @@ void Assert_Throw(int failed, const char *exp, const char *func, const char *fil printer << ", " << str; } printer << "), function " << func << ", file " << file << ", line " << line << "."; - throw std::runtime_error(printer); + throw mediakit::AssertFailedException(printer); } } } diff --git a/src/Common/macros.h b/src/Common/macros.h index e33e1641..dd9ad64d 100644 --- a/src/Common/macros.h +++ b/src/Common/macros.h @@ -80,6 +80,13 @@ extern void Assert_Throw(int failed, const char *exp, const char *func, const ch namespace mediakit { +class AssertFailedException : public std::runtime_error { +public: + template + AssertFailedException(T && ...args) : std::runtime_error(std::forward(args)...) {} + ~AssertFailedException() override = default; +}; + extern const char kServerName[]; template diff --git a/src/Rtp/PSDecoder.cpp b/src/Rtp/PSDecoder.cpp index ecad9e88..a9a5beba 100644 --- a/src/Rtp/PSDecoder.cpp +++ b/src/Rtp/PSDecoder.cpp @@ -63,7 +63,7 @@ const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) { //解析失败,丢弃所有数据 return data + len; - } catch (std::exception &ex) { + } catch (AssertFailedException &ex) { InfoL << "解析 ps 异常: bytes=" << len << ", exception=" << ex.what() << ", hex=" << hexdump(data, MIN(len, 32));