Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
How to catch JavaScript errors globally without try catch

I have a SPA built with Lightning web components. My basic requirement is to catch any kind of JavaScript exceptions or errors and log them, without having to go to each inner component and wrap every piece of JS code in try catch.

I have tried using window.onerror but I am not getting the proper error message with this, it gives message as "Script error." and line no, col no as 0. Looks like some issue with same origin policy

Can any of you please suggest some other effective way to catch any kind of JavaScript errors globally ?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

As far as I know, this is the only way. Could you please provide the code that you are currently using?

I'll include here the way that i had implemented it.

<script>
        window.onerror = function (message, source, lineno, colno, error) {
            console.log(`Error: ${error.message} on line: ${lineno} \nfull message: ${error}`)
            return true;
          };

          function triggerError() {
            x();
          }

          triggerError()
</script>

Output: Error: x is not defined on line: 17 full message: ReferenceError: x is not defined

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda