Example one:
function message () { try { adddlert ("Welcome guest!") ) } catch(err) { txt= "There is an error on this page. \ n \ nthe " txt+ =" Error description: "+ Err.Description +" \ n " txt + =" Click OK to continue. \ n \ nthe " alert (TXT) }}
Example Two:varArray =NULL;Try{document.write (array[0]);} Catch(Err) {Document.writeln ("Error Name:" + err.name + ""); Document.writeln ("Error message:" +err.message);}finally{alert ("Object is null");} Program execution Process1. array[0] The array is an empty object and is called in the program because it does not create array arrays Array[0] will produce an object is null exception2.Catch(ERR) statement captures this exception by Err.name printing the error type, Err.message prints the details of the error.3. Finally similar to the finally Java, no exception will be executed.
Use of Try Catch finally in JavaScript