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));