i m getting error in firebug console
uncaught exception: [Exception... "'Invalid save data.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: chrome://firebug/content/spy.js :: callPageHandler :: line 744" data: no]
When i put this code
value = key+'^_^'+value;
But when i modify this code and put
value = key
the error removes.
so does this error affect my code?
I have an inkling that this might be a good place for exceptions. Exceptions allow you catch errors, which in Javascript is very handy indeed because it also allows you to execute altetrnative code if your browser doesn't support what you are trying to do.
try {
somethingThatOnlyWorksInChrome();
}
catch (ex) {
worksInEverythingElse();
}
Related
I am trying to run the MDB example extension at https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_second_WebExtension and it always fails with the message:
Failed to execute beastify content script unexpected token: ':'
The other message in the console says. scriptElement:88:13
I thought the error message comes from the : in the line but even removing it still gives the message, so there must be something passed in the string error.message that is causing the error.
The whole project is at https://github.com/mdn/webextensions-examples/tree/master/beastify and the error is from choose_beast.js line 88.
From what I see the ${error.message} contains some executable string that has a syntax error.
function reportExecuteScriptError(error) {
document.querySelector("#popup-content").classList.add("hidden");
document.querySelector("#error-content").classList.remove("hidden");
console.error(`Failed to execute beastify content script: ${error.message}`);
}
When I turned on the server, it stops if the function JSON.parse() failed to use. Is there any other way to get the return value of JSON.parse()? I want to throw the error when the function doesn't work. When I import data that is not in JSON format, I want to ignore the error in the function.
This can be achieved with a try...catch statement.
The try...catch statement marks a block of statements to try, and specifies a response, should an exception be thrown.
For example, the following code snippet will attempt to parse invalid JSON.
const jsonImportedData = 'not valid JSON';
try {
JSON.parse(jsonImportedData);
} catch(error) {
console.log(error);
}
If you look at the console, you'll see a log with the JSON.parse error message; however, your program will not throw an actual error since it was gracefully handled.
An npm module generates an error of this format.
throw new Error(error.data.errors)
where error.data.errors is
{ email: [ 'is invalid' ] }
When I try to access it in the catch block of my code, it comes up as
[Error: [object Object]]
How can I access the original error / error message from my catch block?
I just did some experimentation and there doesn't seem to be a lot you can do in this case. It looks like JavaScript calls .toString() on the error message when it's thrown. By default, this is "[object Object]" on all objects.
As far as I can tell, the fix would be to open a pull request that changed the throwing of the error to the following:
throw new Error(JSON.stringify(error.data.errors));
With this change, you could parse the JSON upon catching the error.
try {
// Whatever functionality causes the error.
} catch (e) {
var errors = JSON.parse(e.message);
}
How do I listen to an uncaught exception error in meteor?
The errors are of course specific to the cause, so please can you provide a pseudo style code/explanation that states the concept of handling this error.
An example use case:
A user clicks 'logout' but there is an uncaught exception and the user does not get logged out and so the connection to the server remains open.
You can use the callbacks, they usually provide a reason parameter. E.g
Meteor.call("some_random_non_existent_method", function(err, result) {
if(err) return alert(err.reason)
});
Most meteor callbacks have a error param. With the logout its Meteor.logout(function(err) { ... })
You should be able to catch most types of errors like this. If you want to capture all errors you can use try..catch. Everything in the try block will try to run until it throws an error. You can catch this and provide feedback to the user.
try {
//This will throw an error
this.run_something.go_make_error()
}catch(e) {
alert("There was an error running this");
}
The following js method does not return, yet firebug reports no exception:
function test_contains_doesNotBailWithoutException() {
$.contains(document.getElementById('navlinks', undefined));
// This line should be reached, or you should get an exception message in Firebug.
return true;
}
where navlinks is something that exists on the page, and $ is from jquery 1.5.1. The method exits (throws, I assume) while calling the contains method, in line 4639 of jquery1.5.1:
return !!(a.compareDocumentPosition(b) & 16);
where a is the navlinks div and b is undefined. Shouldn't firebug report an exception in the console?
To be sure, running the following in the firebug console yields neither an error message nor a return result:
return document.getElementById('navlinks').compareDocumentPosition(undefined);
EDIT: I'm using Firefox 4.0.1 and Firebug 1.7.1.
Yes, there should be an exception; I certainly get one with either the JavaScript version:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOM3Node.compareDocumentPosition]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: javascript:alert(document.body.compareDocumentPosition(undefined)) :: <TOP_LEVEL> :: line 1" data: no]
or the same thing from the jQuery version (which has a bracket in the wrong place in your example... not that it matters since the missing argument will naturally get filled in with undefined anyway):
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOM3Node.compareDocumentPosition]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js :: <TOP_LEVEL> :: line 16" data: no]