Exception-1

 

In this example, We have a function call inside try statement and we have catch block with statement that will print the error message. There is no defination of ShowMessage() so call to this method will throw the error message. See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> </head> <body> <p id="sample"></p> <script> try { ShowMessage("This function is not defined anywhere so it will go to catch statement and execute the statements of catch block."); } catch(err) { document.getElementById("sample").innerHTML = err.message; } </script> </body> </html>
Output