Yes, you can use try/catch but remember that this will only handle otherwise uncaught javascript errors. It won't handle socalled "silent failures" as can arise in jQuery which is, to a certain extent, error tolerant.
For example, if jQueryUI was not installed on the page, then try { $('#myDiv').dialog('open'); } would throw a catchable error. However, if jQueryUI was installed but #myDiv did not exist, then failure would be silent; you would need to test for this failure and throw your own error.
try {
$dialog = $('#myDiv').dialog({ autoOpen:false });
if ( $dialog.length == 0 ) {
throw "Dialog not found";
}
else {
$dialog.dialog('open');
}
}
catch(e){
window.open(.....);
} Whereas this is the most likely type of silent failure, there may be others. You will need to research and/or test rigorously to find out what they might be.Airshow
Airshow
WiFi Lounge Lizard
Moderator
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372