Jump to content

Try & Catch


Mikeyham
 Share

Recommended Posts

Why is there a "+" before the equal sign in this try & catch statement?

catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Error description: " + err.description + "\n\n";  txt+="Click OK to continue.\n\n";  alert(txt);  }

~Thanks!

Link to comment
Share on other sites

I see. I also have another question about the Try & Catch tutorial.

catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Click OK to continue viewing this page,\n";  txt+="or Cancel to return to the home page.\n\n";  if(!confirm(txt))	{	document.location.href="http://www.w3schools.com/";	}

Why is there an "!" before the word "confirm" and, if we are confirming, why is it that when you hit cancel it runs the code?

Link to comment
Share on other sites

I see. I also have another question about the Try & Catch tutorial.
catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Click OK to continue viewing this page,\n";  txt+="or Cancel to return to the home page.\n\n";  if(!confirm(txt))	{	document.location.href="http://www.w3schools.com/";	}

Why is there an "!" before the word "confirm" and, if we are confirming, why is it that when you hit cancel it runs the code?

Because "!" means "not". It returns the opposite value of the variable that it's negating.If confirm(txt) is true, !confirm(txt) is false.
Link to comment
Share on other sites

Because "!" means "not". It returns the opposite value of the variable that it's negating.If confirm(txt) is true, !confirm(txt) is false.
Coolio. That's all. Thanks for the help!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...