Unexpected Exception thrown, even after check.
I have the following code whereby an Exception is thrown even after check to prevent an exception from being thrown.
In this code, if function setupSearchBar() is not defined, then do not call this function:
However, what occurs is an Exception is thrown from the if conditional statement because setupSearchBar is not defined:
if (setupSearchBar != undefined)
alert("setupSearchOnLoad: Exception: "+ex.name+": "+ex.message);
Exception.message: "setupSearchBar is not defined"
Why would this occur?
Jeff in Seattle
It is usually an error to use an undeclared variable in an expression.
You could use the typeof operator, which is made to handle undeclared types as undefined.
if(typeof setupSearchBar !='undefined')
If it is a global you could reference it to the window-
Works like a charm! Thanks for the feedback!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread