Q:

Add Try Catch to Javascripts with SRC

I have these CODE#1 scripts and the first script has a source that is running on a web service. I need to have a try catch so when the web service goes to a site down, I can make an else condition like in CODE#2. How can I achieve this. Thanks
CODE #1
<script type="text/javascript" language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity">
</script>
<script type="text/javascript" language="Javascript">
document.write("<p>Welcome to visitors from "+sGeobytesCity+", " + sGeobytesCountry);
</script>

CODE #2
TRY
{
<script type="text/javascript" language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity">
</script>
<script type="text/javascript" language="Javascript">
document.write("<p>Welcome to visitors from "+sGeobytesCity+", " + sGeobytesCountry);
</script>
}
catch
{
window.location = "geobytes.aspx";
}

A:

You can’t use try/catch this way. (Especially since you put it outside of the script elements, so it would be part of the HTML code, and HTML is not a programming language and knows no such thing as a try/catch construct.)
But if the first script is supposed to create the variables sGeobytesCity and sGeobytesCountry that your second script is trying to output, you could check whether they exist or not first in your second script:
if(typeof sGeobytesCity !== "undefined") {
  document.write("<p>Welcome to visitors from "+sGeobytesCity+", " +
    sGeobytesCountry);
}
else {
  window.location.href = "geobytes.aspx";
}

