I have this line come up in the console, only in Firefox, from my JavaScript application I'm developing:
It seems relatively harmless, but I'm curious if there's any way to deduce its origin, because it must come from somewhere, even if it claims 'unknown'. Wrapping the entire script in a try/catch block and toggling Firefox's "Pause on Exception" setting doesn't do anything, which seems to imply it's a special exception? I have some ideas what parts of my code might be causing it that are using Working Draft APIs, but I'm more interested in why it reports this way and what I can do about it. Does Firefox not provide any more detail?
I have this line come up in the console, only in Firefox, from my JavaScript application I'm developing:
It seems relatively harmless, but I'm curious if there's any way to deduce its origin, because it must come from somewhere, even if it claims 'unknown'. Wrapping the entire script in a try/catch block and toggling Firefox's "Pause on Exception" setting doesn't do anything, which seems to imply it's a special exception? I have some ideas what parts of my code might be causing it that are using Working Draft APIs, but I'm more interested in why it reports this way and what I can do about it. Does Firefox not provide any more detail?
Share Improve this question edited Apr 16, 2019 at 11:29 TheMaster 50.5k7 gold badges69 silver badges98 bronze badges asked Jan 6, 2017 at 4:49 MattTreichelMattTreichel 1,5634 gold badges21 silver badges37 bronze badges 5- 1 Use a different browser - Chrome will sometimes help you debug issues that Firefox (or Firebug) will not catch. – user2182349 Commented Jan 6, 2017 at 4:58
- 2 @user2182349 Well, this issue doesn't appear in Chrome at all. It's not really critical to solve, I'm just curious if there's any way to interact with a problem like this or why Firefox does it. – MattTreichel Commented Jan 6, 2017 at 17:41
- 1 when you open Debugger, on the debugger tab, when you click on the gear on the right hand side. there is an option called, pause on exception also want to deselect ignore caught exceptions, then reload page – tik27 Commented Jan 18, 2017 at 0:26
- 1 I once had a problem like that. It was because of Firefox limitation for the size of documents, which I believe it was 768k. Check the size of the document you're retrieving. – Luís Assunção Commented Jan 18, 2017 at 15:23
- @tik27 Ah, that's the obvious sort of thing I'm didn't know about, thanks. Trying it though, it seems to ignore these "uncaught exception"s. So there's something irregular about them. If "Ignore Caught Exceptions" is checked it makes no difference either, but seems funny that if it's checked - the pausing explicitly ignores what Firefox itself calls an "uncaught" exception. – MattTreichel Commented Jan 19, 2017 at 17:10
3 Answers
Reset to default 4 +25There's a few ways you could try to squash this bug.
One thing that's very tedious but will get you the line number of the exception is code that looks like:
foo();
console.log("Line 1");
bar();
console.log("Line 2");
baz();
console.log("Line 3");
and so on, and if you get this in the console:
Line 1
Line 2
Uncaught exception: undefined
then you know that baz() was causing the error. Another way is to use the debugger, like so:
debugger;
foo();
bar();
baz();
and you can use firefox's debugger to go over each line and see which one throws the error to the console.
If you have a lot of code, you could try the divide-and-conquer trick, like this:
var fooStr = foo();
var fooArr = fooStr.split("");
fooArr = fooArr.reverse();
foo(fooArr.join(""));
console.log("Block one");
var barStr = bar();
var barArr = barStr.split("");
barArr = barArr.reverse();
bar(barArr.join(""));
console.log("Block two");
var bazStr = baz();
var bazArr = bazStr.split("");
bazArr = bazArr.reverse();
baz(bazArr.join(""));
console.log("Block three");
Then, if the console looks like this:
Block one
Uncaught exception: undefined
Then the problem is in block 2. Then, you could do this:
var barStr = bar();
console.log("Line 1");
var barArr = barStr.split("");
console.log("Line 2");
barArr = barArr.reverse();
console.log("Line 3");
bar(barArr.join(""));
console.log("Line 4");
console.log("Block two");
console.log("Line 5");
And if you see:
Line 1
Uncaught exception: undefined
Then you know that var barArr = barStr.split("");
is your problem. From then, you might want to log variable values, like this:
console.log(barStr);
var barArr = barStr.split("");
And if you see this in the console:
undefined
Uncaught exception: undefined
Then you know that bar()
is returning undefined
(instead of a string), which does not have a split
method. Then you look at the code of bar to determine if, say you forgot a parameter? Mabey bar
looks like this:
function bar(value){
return strings[value];
}
and strings
is an object with something in it. Therefore, strings[undefined]
will return undefined
, which does not have a split
method. Bug squashed!
I have found a simple example that reproduces the error you see.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
throw undefined
</script>
</head>
<body>
</body>
</html>
The firefox console shows:
uncaught exception: undefined (unknown)
Which is exactly what you get. This leads me to believe that the error occurs in a script that was embedded in your html.
Knowing that you may want to move all such scripts to their own files so that you can debug your code normally.
UPDATE
Accidentally I have found another way you can get such an error. And it comes in the form of eval
.
index.html
<!doctype html>
<html>
<head>
<script src="script.js"></script>
</head>
<body></body>
</html>
script.js
eval('throw undefined');
You could go to about:config and create a boolean preference dom.report_all_js_exceptions.
This will force a lot more exceptions will show up in Error Console.
https://developer.mozilla.org/en-US/docs/Archive/Mozilla/Exception_logging_in_JavaScript