Click here to Skip to main content
13,260,383 members (41,738 online)
Click here to Skip to main content
Add your own
alternative version

Stats

2.6K views
Posted 11 Oct 2013

Avoid errors in Javascript

, 11 Oct 2013
Rate this:
Please Sign up or sign in to vote.
Many times we see some annoying javascript errors on websites. I am of the opinion that the javascript errors should not be shown to users. Best

Editorial Note

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Many times we see some annoying javascript errors on websites.

I am of the opinion that the javascript errors should not be shown to users. Best way is to write correct javascript, but to be on safer side we can write try...catch in javascript to supress the error.

 try
  {
  //Run some code here
  }
catch(err)
  {
  //Just ignore...don't do anything 

 //Or try to handle the error 
  }

 Alternatively we can handle the onerror event and supress all Javascript errors occuring on the page.

<script type="text/javascript">

window.onerror=function(){
//Don't do anything, just supress the error
}

</script>

I hope this helps.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ASP.NET Community
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Collaborative Group

764 members


You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 11 Oct 2013
Article Copyright 2013 by ASP.NET Community
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid