title: handle electron `webContent.executeJavaScript` exception
body: <p>I just started playing with electron and as a playground I opted to draft a raw basic javascript console.</p>
  <p>The code is entered on a <code>&lt;textarea&gt;</code> and once a button is pushed the code gets executed with <em>webContent.executeJavaScript</em> and the result is shown in an output <code>&lt;div/&gt;</code>. Clearly enough I would also like to show as output any eventual error message.</p>
  <p>Not being able to find in the electron documentation a clear way to do it I came up with a solution (below reduced to the bare minimum) which does not really make me happy:</p>
  <pre class="lang-js prettyprint-override"><code>// main.js
  ipcMain.handle('runjs', (event, code ) =&gt; 
      mainWindow.webContents.executeJavaScript(code, true)
  );
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// preload.js
  const { ipcRenderer, contextBridge } = require('electron');
  
  contextBridge.exposeInMainWorld('api', {
      runjs: code =&gt; ipcRenderer.invoke('runjs', code),
  });
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// triggering component
  import React from 'react'
  
  export default ({code}) =&gt; {
      const onClick = () =&gt; window.api.runjs(`
          (() =&gt; {
              try {
                  var t = eval('${code.replace(/\n|\r/mg, '')}');
                  return { result: t }
              } catch (e) {
                return { error: e }
              }
            })()
      `).then(res =&gt; {
          // dispatch to decide what to do in case of 'error' or 'result' in res
          /// and consume the result in the output
      })
      .catch(e =&gt; {
          // not useful to understand the code error
      })
      return &lt;button onClick={onClick}&gt;RUN&lt;/button&gt;
  )
  
  </code></pre>
  <p>It's working but I am sure there has to be a better way.</p>
  <p>How should that be properly handled ?</p>