MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / Error__New

Method Error__New

source/script2.cpp:16692–16771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16690
16691
16692ResultType Object::Error__New(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
16693{
16694 LPTSTR message;
16695 TCHAR what_buf[MAX_NUMBER_SIZE], extra_buf[MAX_NUMBER_SIZE];
16696 LPCTSTR what = ParamIndexToOptionalString(1, what_buf);
16697 Line *line = g_script.mCurrLine;
16698
16699 if (aID == M_OSError__New && (ParamIndexIsOmitted(0) || ParamIndexIsNumeric(0)))
16700 {
16701 DWORD error = ParamIndexIsOmitted(0) ? g->LastError : (DWORD)ParamIndexToInt64(0);
16702 SetOwnProp(_T("Number"), error);
16703
16704 // Determine message based on error number.
16705 DWORD message_buf_size = _f_retval_buf_size;
16706 message = _f_retval_buf;
16707 DWORD size = (DWORD)_sntprintf(message, message_buf_size, (int)error < 0 ? _T("(0x%X) ") : _T("(%i) "), error);
16708 if (error) // Never show "Error: (0) The operation completed successfully."
16709 size += FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, message + size, message_buf_size - size, NULL);
16710 if (size)
16711 {
16712 if (message[size - 1] == '\n')
16713 message[--size] = '\0';
16714 if (message[size - 1] == '\r')
16715 message[--size] = '\0';
16716 }
16717 }
16718 else
16719 message = ParamIndexIsOmitted(0) ? Type() : ParamIndexToString(0, _f_number_buf);
16720
16721#ifndef CONFIG_DEBUGGER
16722 if (ParamIndexIsOmitted(1) && g->CurrentFunc)
16723 what = g->CurrentFunc->mName;
16724 SetOwnProp(_T("Stack"), _T("")); // Avoid "unknown property" in compiled scripts.
16725#else
16726 DbgStack::Entry *stack_top = g_Debugger.mStack.mTop - 1;
16727 if (stack_top->type == DbgStack::SE_BIF && _tcsicmp(what, stack_top->func->mName))
16728 --stack_top;
16729
16730 if (ParamIndexIsOmitted(1)) // "What"
16731 {
16732 if (g->CurrentFunc)
16733 what = g->CurrentFunc->mName;
16734 }
16735 else
16736 {
16737 int offset = ParamIndexIsNumeric(1) ? ParamIndexToInt(1) : 0;
16738 for (auto se = stack_top; se >= g_Debugger.mStack.mBottom; --se)
16739 {
16740 if (++offset == 0 || !_tcsicmp(se->Name(), what))
16741 {
16742 line = se > g_Debugger.mStack.mBottom ? se[-1].line : se->line;
16743 // se->line contains the line at the given offset from the top of the stack.
16744 // Rather than returning the name of the function or sub which contains that
16745 // line, return the name of the function or sub which that line called.
16746 // In other words, an offset of -1 gives the name of the current function and
16747 // the file and number of the line which it was called from.
16748 what = se->Name();
16749 stack_top = se;

Callers

nothing calls this directly

Calls 2

GetScriptStackFunction · 0.85
NameMethod · 0.45

Tested by

no test coverage detected