Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda