| 24990 | } |
| 24991 | |
| 24992 | inline protected_function_result script_throw_on_error(lua_State* L, protected_function_result result) { |
| 24993 | type t = type_of(L, result.stack_index()); |
| 24994 | std::string err = "sol: "; |
| 24995 | err += to_string(result.status()); |
| 24996 | err += " error"; |
| 24997 | #if SOL_IS_ON(SOL_EXCEPTIONS_I_) |
| 24998 | std::exception_ptr eptr = std::current_exception(); |
| 24999 | if (eptr) { |
| 25000 | err += " with a "; |
| 25001 | try { |
| 25002 | std::rethrow_exception(eptr); |
| 25003 | } |
| 25004 | catch (const std::exception& ex) { |
| 25005 | err += "std::exception -- "; |
| 25006 | err.append(ex.what()); |
| 25007 | } |
| 25008 | catch (const std::string& message) { |
| 25009 | err += "thrown message -- "; |
| 25010 | err.append(message); |
| 25011 | } |
| 25012 | catch (const char* message) { |
| 25013 | err += "thrown message -- "; |
| 25014 | err.append(message); |
| 25015 | } |
| 25016 | catch (...) { |
| 25017 | err.append("thrown but unknown type, cannot serialize into error message"); |
| 25018 | } |
| 25019 | } |
| 25020 | #endif // serialize exception information if possible |
| 25021 | if (t == type::string) { |
| 25022 | err += ": "; |
| 25023 | string_view serr = stack::unqualified_get<string_view>(L, result.stack_index()); |
| 25024 | err.append(serr.data(), serr.size()); |
| 25025 | } |
| 25026 | #if SOL_IS_ON(SOL_PRINT_ERRORS_I_) |
| 25027 | std::cerr << "[sol3] An error occurred and has been passed to an error handler: "; |
| 25028 | std::cerr << err; |
| 25029 | std::cerr << std::endl; |
| 25030 | #endif |
| 25031 | // replacing information of stack error into pfr |
| 25032 | int target = result.stack_index(); |
| 25033 | if (result.pop_count() > 0) { |
| 25034 | stack::remove(L, target, result.pop_count()); |
| 25035 | } |
| 25036 | stack::push(L, err); |
| 25037 | int top = lua_gettop(L); |
| 25038 | int towards = top - target; |
| 25039 | if (towards != 0) { |
| 25040 | lua_rotate(L, top, towards); |
| 25041 | } |
| 25042 | #if SOL_IS_OFF(SOL_EXCEPTIONS_I_) |
| 25043 | return result; |
| 25044 | #else |
| 25045 | // just throw our error |
| 25046 | throw error(detail::direct_error, err); |
| 25047 | #endif // If exceptions are allowed |
| 25048 | } |
| 25049 |
no test coverage detected