Thanks to the fact that Safari and other browsers have decided that
window.onerror is not worth supporting, I'm looking for a clean(er)
way to catch errors than simply tossing try/except blocks in every
single function. My initial thought (which strikes me as poor, hence
this post) is something like
function invoke( func_name ) {
var args=[];
for( var idx=1; idx < arguments.length; idx++ ) {
args.push( arguments[idx] );
}
try {
window[func_name].apply( null, args );
}
catch( ex ) {
if( windowOnErrorSupported ) { // figure this out elsewhere
throw ex; // Allow existing code to handle
}
else {
alert( 'Script error in '+func+': '+ex.message );
}
}
}
The creation of an array every time a function is called is what
really sours me on this idea. Also, I'm wondering about how to
determine whether window.onerror will actually work without detecting
the browser type. Obviously I could intentionally generate a script
error and see if it were properly handled by a dummy window.onerror,
but that also strikes me as a bad idea. Thanks heartily in advance
for any ideas.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.