Like the Object oriented programming the exception handling is also not used while coding in JavaScript. That why in most of cases if there is any problem in one part in a page then surprisingly other part also stops working. In this post we will be discussing the various techniques to handle exceptions in JavaScript.

Using try..catch block

try..catch block in JavaScript is very much similar to the regular C# try..catch block. The suspected code will be put in try block and all exceptions which will occur in the try block will be caught in catch block.

Using onerror event

onerror event will be raised each time there is any error while performing a action in the document. This like on place exception handling similar to Application_Error in ASP.NET. Here is sample code which demonstrate this:

Nice post on error catching. I'm building a service that lets people instrument their website to catch Javascript errors (development & production), logging them to a hosted server (Issue management UI, etc). I'm trying to collect early alpha feedback.. it's 1 line of JS code, would be great if you wanted to give it a whirl; Rerrorize.com

Hi Guys,A runtime error which causes to break the execution of a program is known as exception and mechanism to handle this exception so that program did not terminate abnormally is known as Exception handling........for more details check out the following link.......http://mindstick.com....20in%20Java%20Script

We've been building a SaaS solution for this for some time http://muscula.com. It works like google analytics, just copy a script to your page and you're logging.

We've found that the hardest part of having a great JavaScript error log is not logging the errors. There is a ton of other stuff you need to do. One big problem is that browsers log the errors very differently, so grouping them intelligently is very hard, we've spend months on this analyzing millions of JavaScript errors. Our algorithm is good now, but we've concluded that refinining this grouping logic will never be done. Another big problem with JavaScript error logs is all the noise generated from browser plugins. They account for 10-20% of all errors logged. Building our relevance filter that filters all this noise away has been a big task to. And then there is stuff like prettyprinting minified JavaScript when you show the location of the error in the code, integration with GA and more.

We log in more advanced ways than just onerror to get real call stacks and more information, but compared to not logging at all, a homebrewed solution that logs onerror is great. I highly suggest to anyone to log these errors, you'll be surprised at how many errors actually occur.

We're in private beta at the moment, but working very hard on launching.

It's a bit more complex to log the clientside errors, supporting all the major browsers and mobile devices. We built http://jslogger.com to take care about that. It's also possible to log the backend errors with the NodeJS library. Worth to give it a try.