0% found this document useful (0 votes)
5 views20 pages

3.3 Java Script Exception Handling

Module III covers JavaScript Exception Handling, detailing the types of errors, including syntax, runtime, and logical errors, as well as the use of throw, try, catch, and finally statements for error management. It also discusses debugging techniques such as using console.log() and alert() for identifying issues in code. The module includes references for further reading on web programming and JavaScript.

Uploaded by

mvishal.2025aids
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

3.3 Java Script Exception Handling

Module III covers JavaScript Exception Handling, detailing the types of errors, including syntax, runtime, and logical errors, as well as the use of throw, try, catch, and finally statements for error management. It also discusses debugging techniques such as using console.log() and alert() for identifying issues in code. The module includes references for further reading on web programming and JavaScript.

Uploaded by

mvishal.2025aids
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Module III: Java Script Exception Handling

Debugging
U23CS381 -
ADD

16-11- Java Script Exception 1


2023 Handling
Agend
a 🞇 Introduction
🞇 Types of
Errors
🞇 JavaScript Errors C ategorization
🞇 throw Statement
🞇 try Statement
🞇 catch Statement
🞇 finally Statement
🞇 Types of Exception Handling Statements
Debugging

Java Script Exception


Handling
Challenge
time:
 Form Validation
 Page Redirect

Java Script Exception


Handling
Introductio
n:Exception handling is a
 process or method used for handling
the abnormal statements in the program and executing
them.
 It also enables to handle the flow control of the program.
 For example, the Division of a non-zero value with zero will
result in infinity always, and it is an exception. Thus, with the
help of exception handling, it can be executed and
handled.
 Exception Handling is implemented using throw{}, try{},
catch{}
and finally{}.
Java Script Exception
Handling
Types of
Errors:
 Syntax Error: When a user makes a mistake in the pre-defined
syntax of a programming language, a syntax error may
appear.
 Runtime Error: When an error occurs during the program’s
execution, such an error is known as Runtime error. The codes
which create runtime errors are known as Exceptions. Thus,
exception handlers are used for handling runtime errors.
 Logical Error: An error that occurs when there is any logical
mistake in the program that may not produce the desired
output and may terminate abnormally. Such an error is known
as a Logical error.
Java Script Exception
Handling
Error
Object:
 When a runtime error oc curs, it creates and throws an
Error object.
 Such an object can also be used as a base for the user-
defined exceptions.
 An error object has two properties:
 name: This object property sets or returns an error name.
 message: This property returns an error message in the string
form.

Java Script Exception


Handling
JavaScript Errors
Categorization:
 EvalError: It creates an instance for the error in the eval(),
a global function for evaluating the JavaString string code.
 InternalError: It creates an instance when the JavaString
engine throws an internal error.
 RangeError: It creates an instance for the error when a
numeric variable or parameter is out of its valid range.
 ReferenceError: It creates an instance for the error that
occurs when an invalid reference is de-referenced.

Java Script Exception


Handling
JavaScript Errors Categorization
(Cont..,):
 SyntaxError: An instance is created for the syntax error that
may oc cur while parsing the eval().
 TypeError: When a variable is not a valid type, an instance
is created for such an error.
 URIError: An instance is created for the error that occurs
when invalid parameters are passed in encodeURI() or
decodeURI().

Java Script Exception


Handling
throw{}
statement:
 Throw statement is used for throwing user-defined errors.
 User can define and throw their own custom errors.
 When a throw statement is executed, the statements
present after it will not execute. The control will directly
pass to the catch block.
 Syntax:
throw exception;

Java Script Exception


Handling
try{}
statement:
 The code that needs possible error testing is kept within the
try block.
 If any error occurs, it passes to the catch{} block for taking
suitable actions and handling the error. Otherwise, it
executes the code written within.

Java Script Exception


Handling
catch{}
statement:
 catch block handles the error of the c ode by executing the
set of statements written within the block.
 catch block contains either the user-defined exception
handler or the built-in handler.
 This block executes only when any error-prone code needs
to be handled in the try block. Otherwise, the catch block
is skipped.
 catch {} statement executes only after executing
the try
{} statement. Also, one try block can contain
one or more catch blocks.
Java Script Exception
Handling
finally{}
statement:
 Finally is an optional block of statements that is executed
after the execution of try and catch statements.
 Finally block does not hold for the exception to be thrown.
 Any exception is thrown or not, finally block code, if present,
will definitely execute. It does not care for the output either.

Java Script Exception


Handling
Types of Exception Handling
Statements:
 throw statements
 try…catch statements
 try… catch… finally
statements.

Java Script Exception


Handling
Debugging
Debugging is the process of finding and fixing errors (bugs) in
your code.
In JavaScript, debugging helps identify:

Syntax errors

Logical errors

Runtime errors
Debugging
Using console.log()

The simplest and most common method.

let a = 5, b = 10;
console.log("Value of a:", a);
console.log("Value of b:", b);
console.log("Sum:", a + b);

You can use console.error() for errors and console.warn() for


warnings.
Using alert() for Quick Debugging
let name = "John";
alert("User name is: " + name);

A popup showing User name is: John

Using Try...Catch for Error


Handling
try {
let result = x + 10; // x is not defined
} catch (error) {
console.error("An error occurred:", error.message);
}
Java Script Exception
Handling
Text Books &
References
TEXT BOOKS:
 Internet & World Wide Web How to Program, 5th edition, by Paul Deitel
Harvey
Deitel, Abbey Deitel, Pearson Publication, 2018.
 App Inventor 2: Create Your Own Android Apps 2nd Edition by David
Wolber, Hal Abelson, Ellen Spertus, Liz Looney, 2014.
REFERENCES:
 CS50's Web Programming with Python and JavaScript
- https://cs50.harvard.edu/web/2020
 “Get Coding! Learn HTML, CSS & JavaScript & Build a
Website, App & Game”
by Young Rewired State, Walker Books, 2016.
 Version Control with Git, by Jon Loeliger, Matthew
McCullough, 2nd Edition,
web-design-course Java Script Exception
2012.
. Handling

 Ultimate web design course:


Java Script Exception
Handling
Java Script Exception
Handling

You might also like