Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:05:33+00:00 2026-06-14T11:05:33+00:00

This may be a bad question, but I’ve noticed that as I’m writing coding

  • 0

This may be a bad question, but I’ve noticed that as I’m writing coding along using mootools When I’ve got some code that goes through callbacks, bindings and generally isn’t just a straight forward function call, if there’s an error it doesn’t get picked up by either Firebug or Chrome’s console it just silently fails, and I’m forced to track down the error using trys and such that don’t give you handy information like the line of code that’s failing. It’s like writing code for IE6 all you have to go on is some opaque message like ‘can not read ‘x’ of undefined.’

I realize that the question isn’t specific enough to ask ‘how do I avoid this’ but does anyone else run into this problem and if so how do you work around it? I’m also a little confused how an error could be picked up by a try/catch block, but not the javascript console.

EDIT:

OK, I’ve come up with something that reproduces the error

say you’ve got a function

function foo(){
   var x = value.blah;
}

if I call that function like foo() I rightly get an reference error in my console. If, however, I call it like

(function(){
   foo.attempt();
})()

I get no error in the console, but if I change foo to be

function foo(){
   try{
   var x = value.blah;
   } catch(e){console.log(e)}
}

the console will log e but of course without the handle ‘line: whatever’ information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:05:35+00:00Added an answer on June 14, 2026 at 11:05 am

    I have considerable experience fiddling with errors in JavaScript. I’ve mostly used Chrome for building my understanding but most of it applies to Firefox and Internet Explorer as well.

    I can immediately debunk your assumption about silent JavaScript errors. They don’t exist, Errors always show. There might be a bug in Firefox or the Chrome’s webdev, but the errors are there.

    The most common way for errors not to show up is because you’re catching them yourself. Perhaps prematurely.

    I’ve figured out what I think is the best strategy for catching errors:

    1. Always throw things that are Errors or inherited from Errors.

    Ex: not: throw "Precondition failed" but throw new Error("Precondition failed").

    This is because Errors are weird in JavaScript (I have no other word for it). If you want a stacktrace (and heaven’s yes you want a stacktrace) you’ll need to throw an Error (and not a string).

    2. Don’t use window.onerror Not much to say here. It’s useless. You have no control over what get’s flung to this function. It might be your code, it might be a broken plugin that a visitor uses. Also, no stacktrace.

    3. Have one (global) error handler / when to catch errors

    JavaScript is event driven. This has some unexpected consequences. Observe the following code:

    try {
        setTimeout(function () {
            throw new Error("nope! :D");
        }, 1);
    } catch (e) {
        console.log(e);
    }
    

    You will not see this error. (Firebug / console will catch it though)

    This is because the inner function runs in it’s own event and the try-catch statement no longer applies to it. The correct way is:

    try {
        setTimeout(function () {
            try {
                throw new Error("nope! :D");
            } catch (e) {
                console.log("Hell yea!", e);
            }
        }, 1);
    } catch (e) {
        console.log(e);
    }
    

    Or just make a function that wraps a function in a try-catch:

    function wrap(wrap_dat_func) {
        return function () {
            try {
                wrap_dat_func.apply(wrap_dat_func, arguments);
            } catch (e) {
                // send to error handler
            }
       }
    }
    

    Use like:

    setTimeout(wrap(function () {
        // etc
    }), 1);
    

    So basically whenever you generate a new event, wrap the callback in your global try catch function. So wrap call to setTimeout, setInterval all DOM related events like onclick onload ondocumentready, also AJAX calls onreadystatechanged.

    How to get proper stacktraces (over events!) is another long winded explanation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may expose my ignorance as a web developer, but that wouldn't exactly
This may be a stupid question, but I'm interested in the performance of using
This may seem like an obvious question but we have a PHP/MySQL app that
This may be a stupid question but I have a code with the following
This may be a simple question but I can;t find the answer anywhere. Here
This may sound like a very generic question but here it goes. I have
this may sound pretty straight forward, but still I want to post this question
This may be a stupid question, but I'm trying to replicate a customer's OpenLDAP
This question may sound cliched, but I am in a situation here. I am
This may be a futile question, but I will ask anyway. I have now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.