MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

JavaScript Tutorial

Error Handling In JavaScript
Previous Home Next

JavaScript provide Error handling that is the process of catching the errors generated by our program It can be used to handle all or some of the errors that can occur in a script.

There are manely three types of errors in javascript

  • Syntax Errors
  • Runtime Errors
  • Logical Errors

There are several ways to test and find errors in Javascript

  • The Try.....Catch statement
  • The throw keyword
  • The onerror event handler

The try block Contains code to be executed.

The catch block Contains code to be executed if an error occurs in the code within the try block.

The throw block allows you to create a custom error.

The onerror event its handle the first feature to facilitate error handling

Syntax of try catch :

try{
code to be executed
}
catch (error){
code to be executed if an error 
occurs in the code within the try block
}

 

Example :

<html>
<head>
<script >

function myFunc()
{
   var a = 500;
   
   try {
      alert("Value of variable a is : " + a );
   } catch ( c ) {
      alert("Error: " + c.description );
   }
}

</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type="button" value="Click " onclick="myFunc();" />
</form>
</body>
</html>

Output :

Click the following to see the result:

Example of onerror event

<html>
<head>
<script>

window.onerror = function () {
   alert("An error occurred.");
}

</script>

<body>
<p>Click the following to see the result:</p>
<form>
<input type="button" value="Click " onclick="myFunc();" />
</form>
</head>
</body>
</html>

Output :

Click the following to see the result:

Previous Home Next