void CalError::setLastError(Code code, const std::string& strFile, int line, const std::string& strText) { if (code >= MAX_ERROR_CODE) { code = INTERNAL; } ErrorState& es = getErrorState(); es.lastErrorCode = code; es.strLastErrorFile = strFile.c_str(); es.lastErrorLine = line; es.strLastErrorText = strText.c_str(); }
void BaseExecutionContext::handleError(const std::string &msg, int errnum, bool callUserHandler, ErrorThrowMode mode, const std::string &prefix) { SYNC_VM_REGS_SCOPED(); int newErrorState = ErrorRaised; switch (getErrorState()) { case ErrorRaised: case ErrorRaisedByUserHandler: return; case ExecutingUserHandler: newErrorState = ErrorRaisedByUserHandler; break; default: break; } ErrorStateHelper esh(this, newErrorState); ExtendedException ee(msg); recordLastError(ee, errnum); bool handled = false; if (callUserHandler) { handled = callUserErrorHandler(ee, errnum, false); } if (mode == AlwaysThrow || (mode == ThrowIfUnhandled && !handled)) { try { if (!Eval::Debugger::InterruptException(String(msg))) return; } catch (const Eval::DebuggerClientExitException &e) {} throw FatalErrorException(msg.c_str()); } if (!handled && (RuntimeOption::NoSilencer || (getErrorReportingLevel() & errnum) != 0)) { try { if (!Eval::Debugger::InterruptException(String(msg))) return; } catch (const Eval::DebuggerClientExitException &e) {} const char *file = NULL; int line = 0; if (RuntimeOption::InjectedStackTrace) { ArrayPtr bt = ee.getBackTrace(); if (!bt->empty()) { Array top = bt->rvalAt(0).toArray(); if (top.exists("file")) file = top.rvalAt("file").toString(); if (top.exists("line")) line = top.rvalAt("line"); } } Logger::Log(Logger::LogError, prefix.c_str(), ee, file, line); } }
bool BaseExecutionContext::callUserErrorHandler(const Exception &e, int errnum, bool swallowExceptions) { switch (getErrorState()) { case ExecutingUserHandler: case ErrorRaisedByUserHandler: return false; default: break; } if (!m_userErrorHandlers.empty() && (m_userErrorHandlers.back().second & errnum) != 0) { int errline = 0; String errfile; Array backtrace; const ExtendedException *ee = dynamic_cast<const ExtendedException*>(&e); if (ee) { ArrayPtr arr = ee->getBackTrace(); if (arr) { backtrace = *arr; Array top = backtrace.rvalAt(0); if (!top.isNull()) { errfile = top.rvalAt("file"); errline = top.rvalAt("line").toInt64(); } } } if (backtrace.isNull()) { backtrace = stackTraceToBackTrace(e.getStackTrace()); } try { ErrorStateHelper esh(this, ExecutingUserHandler); if (!same(f_call_user_func_array (m_userErrorHandlers.back().first, CREATE_VECTOR6(errnum, String(e.getMessage()), errfile, errline, "", backtrace)), false)) { return true; } } catch (...) { if (!swallowExceptions) throw; } } return false; }
CalError::Code CalError::getLastErrorCode() { return getErrorState().lastErrorCode; }
const std::string& CalError::getLastErrorTextInternal() { return getErrorState().strLastErrorText; }
int CalError::getLastErrorLine() { return getErrorState().lastErrorLine; }