Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!