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

Function MainExecuteScript

source/AutoHotkey.cpp:282–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280
281
282int MainExecuteScript()
283{
284
285#ifndef _DEBUG
286 __try
287#endif
288 {
289 // Run the auto-execute part at the top of the script (this call might never return):
290 if (!g_script.AutoExecSection()) // Can't run script at all. Due to rarity, just abort.
291 return CRITICAL_ERROR;
292 // REMEMBER: The call above will never return if one of the following happens:
293 // 1) The AutoExec section never finishes (e.g. infinite loop).
294 // 2) The AutoExec function uses the Exit or ExitApp command to terminate the script.
295 // 3) The script isn't persistent and its last line is reached (in which case an ExitApp is implicit).
296
297 // Call it in this special mode to kick off the main event loop.
298 // Be sure to pass something >0 for the first param or it will
299 // return (and we never want this to return):
300 MsgSleep(SLEEP_INTERVAL, WAIT_FOR_MESSAGES);
301 }
302#ifndef _DEBUG
303 __except (EXCEPTION_EXECUTE_HANDLER)
304 {
305 LPCTSTR msg;
306 auto ecode = GetExceptionCode();
307 switch (ecode)
308 {
309 // Having specific messages for the most common exceptions seems worth the added code size.
310 // The term "stack overflow" is not used because it is probably less easily understood by
311 // the average user, and is not useful as a search term due to stackoverflow.com.
312 case EXCEPTION_STACK_OVERFLOW: msg = _T("Function recursion limit exceeded."); break;
313 case EXCEPTION_ACCESS_VIOLATION: msg = _T("Invalid memory read/write."); break;
314 default: msg = _T("System exception 0x%X."); break;
315 }
316 TCHAR buf[127];
317 sntprintf(buf, _countof(buf), msg, ecode);
318 g_script.CriticalError(buf);
319 return ecode;
320 }
321#endif
322 return 0; // Never executed; avoids compiler warning.
323}

Callers 1

AutoHotkey.cppFile · 0.85

Calls 2

MsgSleepFunction · 0.85
AutoExecSectionMethod · 0.80

Tested by

no test coverage detected