SlideShare a Scribd company logo
2
Most read
3
Most read
15
Most read
JavaScript - Errors &
Exceptions Handling
Java script  errors & exceptions handling
Java script  errors & exceptions handling
Java script  errors & exceptions handling
Here is the try...catch...finally block syntax −
<script type = "text/javascript">
<!--
try {
// Code to run
[break;]
}
catch ( e ) {
// Code to run if an exception occurs
[break;]
}
[ finally {
// Code that is always executed regardless of
// an exception occurring
}]
//-->
</script>
<html>
<head>
<script type = "text/javascript">
function myFunc() {
var a = 100;
alert("Value of variable a is : " + a );
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>
<html>
<head>
<script type = "text/javascript">
function myFunc() {
var a = 100;
try {
alert("Value of variable a is : " + a );
}
catch ( e ) {
alert("Error: " + e.description );
}
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>
<html>
<head>
<script type = "text/javascript">
function myFunc() {
var a = 100;
try {
alert("Value of variable a is : " + a );
}
catch ( e ) {
alert("Error: " + e.description );
}
finally {
alert("Finally block will always execute!" );
}
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>
Java script  errors &amp; exceptions handling
<html>
<head>
<script type = "text/javascript">
function myFunc() {
var a = 100;
var b = 0;
try {
if ( b == 0 ) {
throw( "Divide by zero error." );
} else {
var c = a / b;
}
}
catch ( e ) {
alert("Error: " + e );
}
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>
Java script  errors &amp; exceptions handling
<html>
<head>
<script type = "text/javascript">
window.onerror = function () {
alert("An error occurred.");
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>
Java script  errors &amp; exceptions handling
<html>
<head>
<script type = "text/javascript">
window.onerror = function (msg, url, line) {
alert("Message : " + msg );
alert("url : " + url );
alert("Line number : " + line );
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>

More Related Content

What's hot (20)

PDF
javascript objects
Vijay Kalyan
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PPTX
Javascript event handler
Jesus Obenita Jr.
 
PPTX
Document Object Model (DOM)
GOPAL BASAK
 
PPTX
Event In JavaScript
ShahDhruv21
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PPTX
jQuery
Dileep Mishra
 
PPT
CSS Basics
WordPress Memphis
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PDF
HTML & CSS Masterclass
Bernardo Raposo
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PPT
Introduction to Javascript
Amit Tyagi
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PPTX
Bootstrap 3
Lanh Le
 
PPT
PHP variables
Siddique Ibrahim
 
PPT
Javascript
mussawir20
 
PPTX
Complete Lecture on Css presentation
Salman Memon
 
PPTX
Introduction to php
Taha Malampatti
 
PDF
Basics of JavaScript
Bala Narayanan
 
javascript objects
Vijay Kalyan
 
An Introduction to the DOM
Mindy McAdams
 
Javascript event handler
Jesus Obenita Jr.
 
Document Object Model (DOM)
GOPAL BASAK
 
Event In JavaScript
ShahDhruv21
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
CSS Basics
WordPress Memphis
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
HTML & CSS Masterclass
Bernardo Raposo
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Introduction to Javascript
Amit Tyagi
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
Bootstrap 3
Lanh Le
 
PHP variables
Siddique Ibrahim
 
Javascript
mussawir20
 
Complete Lecture on Css presentation
Salman Memon
 
Introduction to php
Taha Malampatti
 
Basics of JavaScript
Bala Narayanan
 

Similar to Java script errors &amp; exceptions handling (20)

PPTX
Java script events
AbhishekMondal42
 
PPTX
Java script dialog boxes
AbhishekMondal42
 
PPT
JavaScript Training
Ramindu Deshapriya
 
PDF
Java script programms
Mukund Gandrakota
 
PDF
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
DOCX
Borrador del blog
Sena Cedagro
 
PPTX
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
ODP
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios
 
PDF
Javascript basic programs
Digital Shende
 
PPTX
5 .java script events
chauhankapil
 
PPTX
types of events in JS
chauhankapil
 
TXT
Java.script
g Nama
 
TXT
Html
g Nama
 
TXT
Private slideshow
sblackman
 
TXT
Cancer de-prostata-40601330[1]
Ludwing007
 
PDF
Frontin like-a-backer
Frank de Jonge
 
PPTX
Java Script
Kalidass Balasubramaniam
 
PPTX
Java Script (Module 1).pptx
Shehrevar Davierwala
 
DOC
14922 java script built (1)
dineshrana201992
 
Java script events
AbhishekMondal42
 
Java script dialog boxes
AbhishekMondal42
 
JavaScript Training
Ramindu Deshapriya
 
Java script programms
Mukund Gandrakota
 
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
Borrador del blog
Sena Cedagro
 
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios
 
Javascript basic programs
Digital Shende
 
5 .java script events
chauhankapil
 
types of events in JS
chauhankapil
 
Java.script
g Nama
 
Html
g Nama
 
Private slideshow
sblackman
 
Cancer de-prostata-40601330[1]
Ludwing007
 
Frontin like-a-backer
Frank de Jonge
 
Java Script (Module 1).pptx
Shehrevar Davierwala
 
14922 java script built (1)
dineshrana201992
 
Ad

More from AbhishekMondal42 (20)

PPTX
Oss evaluation-certification-oss-financial-advantages
AbhishekMondal42
 
PPTX
Word press 01
AbhishekMondal42
 
PPTX
Word press posts(preview &amp; publish)
AbhishekMondal42
 
PPTX
Word press posts(add , edit , delete post)
AbhishekMondal42
 
PPTX
Word press pages(edit and delete)
AbhishekMondal42
 
PPTX
Word press pages(add)
AbhishekMondal42
 
PPTX
Word press media(add,insert,delete)
AbhishekMondal42
 
PPTX
Word press media library
AbhishekMondal42
 
PPTX
Word press widget management
AbhishekMondal42
 
PPTX
Word press view plugins
AbhishekMondal42
 
PPTX
Word press user roles
AbhishekMondal42
 
PPTX
Word press theme management
AbhishekMondal42
 
PPTX
Word press personal profile
AbhishekMondal42
 
PPTX
Word press moderate comments
AbhishekMondal42
 
PPTX
Word press install plugins
AbhishekMondal42
 
PPTX
Word press edit users
AbhishekMondal42
 
PPTX
Word press edit tags
AbhishekMondal42
 
PPTX
Word press edit links
AbhishekMondal42
 
PPTX
Word press edit comments
AbhishekMondal42
 
PPTX
Word press delete users
AbhishekMondal42
 
Oss evaluation-certification-oss-financial-advantages
AbhishekMondal42
 
Word press 01
AbhishekMondal42
 
Word press posts(preview &amp; publish)
AbhishekMondal42
 
Word press posts(add , edit , delete post)
AbhishekMondal42
 
Word press pages(edit and delete)
AbhishekMondal42
 
Word press pages(add)
AbhishekMondal42
 
Word press media(add,insert,delete)
AbhishekMondal42
 
Word press media library
AbhishekMondal42
 
Word press widget management
AbhishekMondal42
 
Word press view plugins
AbhishekMondal42
 
Word press user roles
AbhishekMondal42
 
Word press theme management
AbhishekMondal42
 
Word press personal profile
AbhishekMondal42
 
Word press moderate comments
AbhishekMondal42
 
Word press install plugins
AbhishekMondal42
 
Word press edit users
AbhishekMondal42
 
Word press edit tags
AbhishekMondal42
 
Word press edit links
AbhishekMondal42
 
Word press edit comments
AbhishekMondal42
 
Word press delete users
AbhishekMondal42
 
Ad

Recently uploaded (20)

PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Horarios de distribución de agua en julio
pegazohn1978
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Dimensions of Societal Planning in Commonism
StefanMz
 

Java script errors &amp; exceptions handling

  • 1. JavaScript - Errors & Exceptions Handling
  • 5. Here is the try...catch...finally block syntax − <script type = "text/javascript"> <!-- try { // Code to run [break;] } catch ( e ) { // Code to run if an exception occurs [break;] } [ finally { // Code that is always executed regardless of // an exception occurring }] //--> </script>
  • 6. <html> <head> <script type = "text/javascript"> function myFunc() { var a = 100; alert("Value of variable a is : " + a ); } </script> </head>
  • 7. <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
  • 8. <html> <head> <script type = "text/javascript"> function myFunc() { var a = 100; try { alert("Value of variable a is : " + a ); } catch ( e ) { alert("Error: " + e.description ); } } </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
  • 9. <html> <head> <script type = "text/javascript"> function myFunc() { var a = 100; try { alert("Value of variable a is : " + a ); } catch ( e ) { alert("Error: " + e.description ); }
  • 10. finally { alert("Finally block will always execute!" ); } } </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
  • 12. <html> <head> <script type = "text/javascript"> function myFunc() { var a = 100; var b = 0; try { if ( b == 0 ) { throw( "Divide by zero error." ); } else { var c = a / b; } } catch ( e ) { alert("Error: " + e ); } } </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
  • 14. <html> <head> <script type = "text/javascript"> window.onerror = function () { alert("An error occurred."); } </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
  • 16. <html> <head> <script type = "text/javascript"> window.onerror = function (msg, url, line) { alert("Message : " + msg ); alert("url : " + url ); alert("Line number : " + line ); } </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>