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

Function script_throw_on_error

3rd_party/lua_sol2/include/sol.hpp:20860–20916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20858 }
20859
20860 inline protected_function_result script_throw_on_error(lua_State*L, protected_function_result result) {
20861 type t = type_of(L, result.stack_index());
20862 std::string err = "sol: ";
20863 err += to_string(result.status());
20864 err += " error";
20865#if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
20866 std::exception_ptr eptr = std::current_exception();
20867 if (eptr) {
20868 err += " with a ";
20869 try {
20870 std::rethrow_exception(eptr);
20871 }
20872 catch (const std::exception& ex) {
20873 err += "std::exception -- ";
20874 err.append(ex.what());
20875 }
20876 catch (const std::string& message) {
20877 err += "thrown message -- ";
20878 err.append(message);
20879 }
20880 catch (const char* message) {
20881 err += "thrown message -- ";
20882 err.append(message);
20883 }
20884 catch (...) {
20885 err.append("thrown but unknown type, cannot serialize into error message");
20886 }
20887 }
20888#endif // serialize exception information if possible
20889 if (t == type::string) {
20890 err += ": ";
20891 string_view serr = stack::get<string_view>(L, result.stack_index());
20892 err.append(serr.data(), serr.size());
20893 }
20894#if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
20895 std::cerr << "[sol2] An error occurred and has been passed to an error handler: ";
20896 std::cerr << err;
20897 std::cerr << std::endl;
20898#endif
20899 // replacing information of stack error into pfr
20900 int target = result.stack_index();
20901 if (result.pop_count() > 0) {
20902 stack::remove(L, target, result.pop_count());
20903 }
20904 stack::push(L, err);
20905 int top = lua_gettop(L);
20906 int towards = top - target;
20907 if (towards != 0) {
20908 lua_rotate(L, top, towards);
20909 }
20910#if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
20911 return result;
20912#else
20913 // just throw our error
20914 throw error(detail::direct_error, err);
20915#endif // If exceptions are allowed
20916 }
20917

Callers 1

script_default_on_errorFunction · 0.85

Calls 11

type_ofFunction · 0.85
removeFunction · 0.85
pushFunction · 0.85
lua_rotateFunction · 0.85
errorClass · 0.85
pop_countMethod · 0.80
stack_indexMethod · 0.45
statusMethod · 0.45
whatMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected