@@ -24,14 +24,7 @@ std::string ValueKindToString(const ValueKind& kind);
2424
2525// 输出脚本调用堆栈,API名称,以及插件名
2626inline void CREATE_EXCEPTION_WITH_SCRIPT_INFO (std::string const & func = {}, std::string const & msg = {}) {
27- auto e = script::Exception (msg);
28- lse::LegacyScriptEngine::getLogger ().error (
29- " script::Exception: {0}\n {1}" ,
30- e.message (),
31- e.stacktrace ()
32- );
33- lse::LegacyScriptEngine::getLogger ().error (" In API: " + func);
34- lse::LegacyScriptEngine::getLogger ().error (" In Plugin: " + getEngineOwnData ()->pluginName );
27+ throw script::Exception (fmt::format (" In API: {}, In Plugin: {}, {}" , func, getEngineOwnData ()->pluginName , msg));
3528}
3629
3730inline void LOG_ERROR_WITH_SCRIPT_INFO (std::string const & func = {}, std::string const & msg = {}) {
@@ -41,7 +34,7 @@ inline void LOG_ERROR_WITH_SCRIPT_INFO(std::string const& func = {}, std::string
4134}
4235
4336// 参数类型错误输出
44- inline void LOG_WRONG_ARG_TYPE (std::string const & func = {}) {
37+ inline void THROW_WRONG_ARG_TYPE (std::string const & func = {}) {
4538 CREATE_EXCEPTION_WITH_SCRIPT_INFO (func, " Wrong type of argument!" );
4639}
4740
@@ -59,111 +52,96 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = {}) {
5952#define CHECK_ARGS_COUNT (ARGS, COUNT ) \
6053 if (ARGS.size() < COUNT) { \
6154 LOG_TOO_FEW_ARGS (__FUNCTION__); \
62- return Local<Value>(); \
6355 }
6456
6557// 检查是否TYPE类型
6658#define CHECK_ARG_TYPE (ARG, TYPE ) \
6759 if (ARG.getKind() != TYPE) { \
68- LOG_WRONG_ARG_TYPE (__FUNCTION__); \
69- return Local<Value>(); \
60+ THROW_WRONG_ARG_TYPE (__FUNCTION__); \
7061 }
7162
7263// 截获引擎异常
7364#define CATCH (LOG ) \
74- catch (const Exception& e) { \
75- ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
76- lse::LegacyScriptEngine::getLogger (). error (e. stacktrace ()); \
77- LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
78- return Local<Value>(); \
65+ catch (script:: Exception const & e) { \
66+ throw e; \
67+ } \
68+ catch (std::exception const & e) { \
69+ throw script::Exception (e. what ()); \
7970 } \
8071 catch (...) { \
81- ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
82- LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
83- return Local<Value>(); \
72+ throw script::Exception (fmt::format (" Unknown exception in {}" , __func__)); \
8473 }
8574
8675// 至少COUNT个参数_Constructor
8776#define CHECK_ARGS_COUNT_C (ARGS, COUNT ) \
8877 if (ARGS.size() < COUNT) { \
8978 LOG_TOO_FEW_ARGS (__FUNCTION__); \
90- return nullptr ; \
9179 }
9280
9381// 检查是否TYPE类型_Constructor
9482#define CHECK_ARG_TYPE_C (ARG, TYPE ) \
9583 if (ARG.getKind() != TYPE) { \
96- LOG_WRONG_ARG_TYPE (__FUNCTION__); \
97- return nullptr ; \
84+ THROW_WRONG_ARG_TYPE (__FUNCTION__); \
9885 }
9986
10087// 检查是否TYPE类型_Setter
10188#define CHECK_ARG_TYPE_S (ARG, TYPE ) \
10289 if (ARG.getKind() != TYPE) { \
103- LOG_WRONG_ARG_TYPE (__FUNCTION__); \
104- return ; \
90+ THROW_WRONG_ARG_TYPE (__FUNCTION__); \
10591 }
10692
10793// 截获引擎异常_Constructor
10894#define CATCH_C (LOG ) \
10995 catch (const Exception& e) { \
110- ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
111- lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
96+ ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
97+ lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
11298 LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
11399 return nullptr ; \
114100 } \
115101 catch (...) { \
116- ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
102+ ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
117103 LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
118104 return nullptr ; \
119105 }
120106
121107// 截获引擎异常_Setter
122108#define CATCH_S (LOG ) \
123109 catch (const Exception& e) { \
124- ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
125- lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
110+ ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
111+ lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
126112 LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
127113 return ; \
128114 } \
129115 catch (...) { \
130- ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
116+ ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
131117 LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
132118 return ; \
133119 }
134120
135121// 截获引擎异常_Constructor
136122#define CATCH_WITHOUT_RETURN (LOG ) \
137123 catch (const Exception& e) { \
138- ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
139- lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
124+ ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
125+ lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
140126 LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
141127 } \
142128 catch (...) { \
143- ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
129+ ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
144130 LOG_ERROR_WITH_SCRIPT_INFO (__FUNCTION__, LOG); \
145131 }
146132
147133// 截获回调函数异常
148134#define CATCH_IN_CALLBACK (callback ) \
149135 catch (const Exception& e) { \
150- ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
151- lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
152- lse::LegacyScriptEngine::getLogger ().error ( \
153- std::string (" In callback for " ) + callback \
154- ); \
155- lse::LegacyScriptEngine::getLogger ().error ( \
156- " In Plugin: " + getEngineOwnData ()->pluginName \
157- ); \
136+ ll::error_utils::printException (e, lse::LegacyScriptEngine::getLogger ()); \
137+ lse::LegacyScriptEngine::getLogger ().error (e.stacktrace ()); \
138+ lse::LegacyScriptEngine::getLogger ().error (std::string (" In callback for " ) + callback); \
139+ lse::LegacyScriptEngine::getLogger ().error (" In Plugin: " + getEngineOwnData ()->pluginName ); \
158140 } \
159141 catch (...) { \
160- ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
161- lse::LegacyScriptEngine::getLogger ().error ( \
162- std::string (" In callback for " ) + callback \
163- ); \
164- lse::LegacyScriptEngine::getLogger ().error ( \
165- " In Plugin: " + getEngineOwnData ()->pluginName \
166- ); \
142+ ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ()); \
143+ lse::LegacyScriptEngine::getLogger ().error (std::string (" In callback for " ) + callback); \
144+ lse::LegacyScriptEngine::getLogger ().error (" In Plugin: " + getEngineOwnData ()->pluginName ); \
167145 }
168146#else
169147
@@ -302,11 +280,7 @@ struct EnumDefineBuilder {
302280 try {
303281 return Number::newNumber (static_cast <int64_t >(val));
304282 } catch (const std::exception&) {
305- lse::LegacyScriptEngine::getLogger ().error (
306- " Error in get {}.{}" ,
307- enumName,
308- name
309- );
283+ lse::LegacyScriptEngine::getLogger ().error (" Error in get {}.{}" , enumName, name);
310284 }
311285 return Local<Value>();
312286 });
0 commit comments