How to stop BrowserWindow from breaking after a single error?

I’m using the executeJavaScript method to control a browser via electron. However, I’ve noticed that the BrowserWindow instance essentially becomes unresponsive after one error occurs. Aside from putting every single line of code in a try/catch block, is it possible to disable this functionality? Specifically, I’d prefer that the BrowserWindow continues to execute future code despite running into an error on a previous request. For example, in the code below, I want the console to successfully output “I’m not being executed”.

const {BrowserWindow, app} = require('electron')
async function main(){
  win = new BrowserWindow({width:1200,height:900, webPreferences: {nodeIntegration: false} });
  await sleep(10000); //letting page load
  await win.webContents.executeJavaScript('console.log("Im being executed")')
  await sleep(2000);//break
  await win.webContents.executeJavaScript('undefinedVar.causeError()')
  await sleep(2000);//break
  await win.webContents.executeJavaScript('console.log("Im not being executed")')
function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms || 0));