Exception handlers enable the programmer to detect errors and then resolve them easily, it helps users who are unware of error messages.
The Statement try is used to enclose and test parts of the program where some problem is expected. If an exception is encountered the control is shifted to catch block.
The catch block is used to enclose statements which specify what went wrong with the program. If no errors are detected, then the catch block is ignored.
The throw statement allows you to create your own conditions for exceptions.
Use it within the try block, to test for a specific error condition and throw it to the catch block.
The finally clause is used to execute statements after the end of try block, whether or not an exception occured within the try block
Syntax: Exception Handling finally clause
The Event handler onerror recieves three argument : error message , URL and line Number. Whenever an error occurs , the event handler is executed after which the browser default behaviour takes over.
The default browser behaviour can be prevented by using the return value of false