Frontend Development 17 min read

Handling Application Crashes in Electron on Windows

The article explains how uncaught exceptions cause Electron app crashes on Windows, describes Windows’ user‑mode dump types, shows how Crashpad generates minidumps via a simple exception filter, demonstrates starting the built‑in crash reporter in JavaScript, and outlines uploading and analyzing dumps with Visual Studio or WinDbg, plus a watchdog restart strategy.

DaTaobao Tech
DaTaobao Tech
DaTaobao Tech
Handling Application Crashes in Electron on Windows

After months of development, a new Electron‑based live‑streaming tool for Taobao was released. Users began reporting frequent crashes, which are caused by uncaught exceptions in the client application.

The article first explains how crashes are generated on Windows. The OS separates kernel mode and user mode; user‑mode applications (such as the Electron live‑streaming client) run in user mode. When a thread started by CreateProcess or CreateThread throws an uncaught exception, the UnHandledExceptionFilter is invoked and the process terminates via ExitProcess . This is analogous to uncaught JavaScript errors in the front‑end.

// Main thread start function
VOID BaseProcessStart(PPROCESS_START_ROUTINE pfnSatrtAddr)
{
    __try {
        ExitThread((pfnSatrtAddr)());
    }
    __except(UnHandledExceptionFilter(GetExceptionInformation())) {
        ExitProcess(GetExceptionCode());
    }
}

// Thread start function
VOID BaseThreadStart(PTHREAD_START_ROUTINE pfnSatrtAddr, PVOID pvParam)
{
    __try {
        ExitThread((pfnSatrtAddr)());
    }
    __except(UnHandledExceptionFilter(GetExceptionInformation())) {
        ExitProcess(GetExceptionCode());
    }
}

Windows creates two kinds of dump files: kernel‑mode dumps (e.g., blue‑screen) and user‑mode dumps. User‑mode dumps can be full dumps (large, detailed) or minidumps (small, containing only essential information such as thread stacks and selected variables). Minidumps are the preferred format for client‑side crash reporting.

The article provides a minidump generation routine used by Crashpad:

LONG WINAPI pExceptionFilter(struct _EXCEPTION_POINTERS* pExceptionInfo){
    HANDLE hFile = ::CreateFile(m_dumpFilePathFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    _MINIDUMP_EXCEPTION_INFORMATION info;
    info.ThreadId = ::GetCurrentThreadId();
    info.ExceptionPointers = pExceptionInfo;
    info.ClientPointers = true;
    ::MiniDumpWriteDump(
        ::GetCurrentProcess(),
        ::GetCurrentProcessId(),
        hFile,
        MiniDumpNormal,
        &info, NULL, NULL);
    ::CloseHandle(hFile);
    return EXCEPTION_EXECUTE_HANDLER;
}

Crashpad, the successor of Breakpad, is integrated into Electron and automatically creates minidump files when the main or renderer process crashes. Developers only need a few lines of JavaScript to start the built‑in crash reporter:

import { crashReporter } from 'electron';
crashReporter.start({
  productName: 'YourApp',
  companyName: 'YourCompany',
  submitURL: 'https://your-domain.com/crash',
  uploadToServer: true
});

Collected dumps can be uploaded to monitoring platforms such as the Alibaba "Rainbird" (雨燕) platform or the "Qianniao" (千鸟) platform. These services provide dashboards for crash details, stack traces, user environment, and raw payloads.

For deeper analysis, developers can use Visual Studio or WinDbg Preview. Both tools require symbol files (.pdb) to resolve function names and line numbers. Symbol sources include the Microsoft PDB server, the Electron symbol server, and local application PDB files.

In Visual Studio, after opening a dump, developers configure symbol paths, load modules, and view the full call stack. They can also set source‑code paths to debug the exact line that caused the crash.

WinDbg Preview offers a lightweight alternative: after loading a dump and configuring symbol servers, the !analyze -v command displays module lists and call stacks. Source paths can also be set for line‑level debugging.

The article concludes with a summary of the crash‑handling workflow, a comparison to front‑end JavaScript error handling, and a forward‑looking suggestion to run a separate watchdog process that restarts the Electron app if it crashes.

debuggingElectronWindowsCrash HandlingCrashpadMinidump
DaTaobao Tech
Written by

DaTaobao Tech

Official account of DaTaobao Technology

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.