Set up global handlers to catch errors that slip through. In browsers, use window.onerror. In Node.js, use process.on('uncaughtException').
window.onerror = function(msg, url, line) {
logToServer({ msg, url, line });
return true; // Prevent default handling
};
Global handlers are a safety net, not a replacement for proper handling.