MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / script_throw_on_error

Function script_throw_on_error

extlibs/sol3/include/sol/sol.hpp:24203–24259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24201 }
24202
24203 inline protected_function_result script_throw_on_error(lua_State*L, protected_function_result result) {
24204 type t = type_of(L, result.stack_index());
24205 std::string err = "sol: ";
24206 err += to_string(result.status());
24207 err += " error";
24208#if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
24209 std::exception_ptr eptr = std::current_exception();
24210 if (eptr) {
24211 err += " with a ";
24212 try {
24213 std::rethrow_exception(eptr);
24214 }
24215 catch (const std::exception& ex) {
24216 err += "std::exception -- ";
24217 err.append(ex.what());
24218 }
24219 catch (const std::string& message) {
24220 err += "thrown message -- ";
24221 err.append(message);
24222 }
24223 catch (const char* message) {
24224 err += "thrown message -- ";
24225 err.append(message);
24226 }
24227 catch (...) {
24228 err.append("thrown but unknown type, cannot serialize into error message");
24229 }
24230 }
24231#endif // serialize exception information if possible
24232 if (t == type::string) {
24233 err += ": ";
24234 string_view serr = stack::unqualified_get<string_view>(L, result.stack_index());
24235 err.append(serr.data(), serr.size());
24236 }
24237#if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
24238 std::cerr << "[sol3] An error occurred and has been passed to an error handler: ";
24239 std::cerr << err;
24240 std::cerr << std::endl;
24241#endif
24242 // replacing information of stack error into pfr
24243 int target = result.stack_index();
24244 if (result.pop_count() > 0) {
24245 stack::remove(L, target, result.pop_count());
24246 }
24247 stack::push(L, err);
24248 int top = lua_gettop(L);
24249 int towards = top - target;
24250 if (towards != 0) {
24251 lua_rotate(L, top, towards);
24252 }
24253#if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
24254 return result;
24255#else
24256 // just throw our error
24257 throw error(detail::direct_error, err);
24258#endif // If exceptions are allowed
24259 }
24260

Callers 1

script_default_on_errorFunction · 0.85

Calls 14

type_ofFunction · 0.85
removeFunction · 0.85
pushFunction · 0.85
lua_gettopFunction · 0.85
pop_countMethod · 0.80
lua_rotateFunction · 0.70
errorClass · 0.70
to_stringFunction · 0.50
stack_indexMethod · 0.45
statusMethod · 0.45
appendMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected