Discussion for domFunction
Before you ask specific technical questions, please read or search through the existing comments, and any available documentation, to see if your question has already been answered.
You can also subscribe to this discussion (RSS 2.0)
-
RE: domFunction: error handling
Posted by Morgan Knicely on 2006-02-21 at 01:24:03 (GMT)
I've noticed that if I use domFunction to call a function that has bugs, the script will loop endlessly inserting error messages in the console as it goes. Eeek! Example:
function snafu() {
blah;
}
var foobar = new domFunction(function() {
snafu();
});So I added a try...catch statement to the portion of domFunction that executes the desired code. Change lines 57-58 of the original script:
//we can call the argument function and clear the timer
if(!c) { f(); clearInterval(t); }To:
//we can call the argument function and clear the timer
if(!c) {
try {
f();
} catch(err) {
alert('Error: ' + err.description);
}
clearInterval(t);
}What do you think of the change? I'm looking into making the alert message more informative, and possibly routing it to the Firefox console when available.
-
RE: domFunction
Posted by brothercake on 2006-02-22 at 08:10:28 (GMT)
What do you think of the change? I'm looking into making the alert message more informative, and possibly routing it to the Firefox console when available.
I like it
I've noticed the same problem, and it can be rather insane, as it loops through the timeout throwing the same error into the console over and over again!
But I hadn't thought of using a
try{} catch{}
construct .. that's probably the way to go, yeah -
RE: domFunction
Posted by johan duflost on 2006-08-03 at 06:01:40 (GMT)
Hello,I get this error message in firefox in the demo page:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line 753" data: no]
-
RE: domFunction
Posted by brothercake on 2006-09-05 at 01:17:53 (GMT)
That error is coming from the Firefox chrome itself; do you have an extensions installed? It's most likely coming from one of them.
-
RE: domFunction
Posted by Jerome on 2006-09-09 at 17:21:36 (GMT)
Just a small suggestion for domFunction... as .js files are loaded asynchronously it would be possible to attempt to call a function, somewhere down the callstack from domFunction, that doesn't actually exist yet. How about expanding the existence checking code to include functions?
//if its value is "id" and the element with the given ID doesn't exist
//or its value is "tag" and the specified collection has no members
if
(
(a[i] == 'id' && document.getElementById(i) == null)
||
(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
||
(a[i] == 'function' && window[i])
)No need to check for all the functions you want to use, of course - just one from any .js file you rely on.
Anyway, just a thought (haven't actually tried it yet!). Thanks for the really useful bit of code
P.S. Looking at the error trapping mod above, it might be slightly better to re-throw like this:
//we can call the argument function and clear the timer
if(!c) {
try {
f();
} catch(err) {
throw err;
} finally {
clearInterval(t);
}
} -
RE: domFunction
Posted by Jerome on 2006-09-09 at 17:24:52 (GMT)
Oops, sorry - that should have been:
//if its value is "id" and the element with the given ID doesn't exist
//or its value is "tag" and the specified collection has no members
//or its value is "function" and the specified function doesn't exist
if
(
(a[i] == 'id' && document.getElementById(i) == null)
||
(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
||
(a[i] == 'function' && !window[i])
)Note the ! before window[i]
-
RE: domFunction
Posted by brothercake on 2006-09-12 at 01:45:35 (GMT)
as .js files are loaded asynchronously it would be possible to attempt to call a function, somewhere down the callstack from domFunction, that doesn't actually exist yet
That's not true - JS files are loaded synchronously unless you use the [unreliable] "defer" attribute.
The problem here is the structure of your codebase; you're relying on dependencies that don't exist when you need them, and that's an architecture issue - something you can resolve manually by attention to dependency structures.
I'm guessing here that you're using a generalised framework like prototype? If so, that certainly won't make your job easier, because following dependency chains in external frameworks can be notoriously difficult (and is, in my view, a reason for not using them; but that's another argument for another time!)
I do appreciate however that a timed solution would fix this potential issue more swiftly in specific cases, but it's really a case of patchwork, of providing a temporary solution to a problem that you'd be much better advised to address at its root.
-
RE: domFunction
Posted by brothercake on 2006-09-12 at 01:47:45 (GMT)
btw, this example:
(a[i] == 'function' && !window[i])
should be like this:
(a[i] == 'function' && typeof window[i] == 'undefined')
But even then, it would of course only work for functions in the window scope.
-
RE: domFunction
Posted by brothercake on 2006-09-12 at 18:46:29 (GMT)
Re: PS - thanks for the
throw
code - that's much better -
Alex
Posted by http://www.google.com on 2007-04-23 at 00:18:46 (GMT)
Thank You
This discussion is now closed
Discussions are usually kept open until they start getting spammed,
which in practice seems to be about 2-3 weeks