0% found this document useful (0 votes)
2 views

2.8 Java Script Exception Handling

The document outlines a module on JavaScript Exception Handling, covering topics such as types of errors, error categorization, and exception handling statements like throw, try, catch, and finally. It emphasizes the importance of handling abnormal statements in programming and provides a structured approach to managing errors. Additionally, it includes course outcomes and references for further reading.

Uploaded by

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

2.8 Java Script Exception Handling

The document outlines a module on JavaScript Exception Handling, covering topics such as types of errors, error categorization, and exception handling statements like throw, try, catch, and finally. It emphasizes the importance of handling abnormal statements in programming and provides a structured approach to managing errors. Additionally, it includes course outcomes and references for further reading.

Uploaded by

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

Module II: Java Script Exception Handling

U23CS381 - ADD Session by


Dr. S. Sampath Kumar, AP/CSE

16-11-2023 Java Script Exception Handling 1


2 16-11-2023

Agenda
 Introduction
 Types of Errors
 JavaScript Errors Categorization
 throw Statement
 try Statement
 catch Statement
 finally Statement
 Types of Exception Handling Statements

Java Script Exception Handling


3 16-11-2023

Module II: Interactive Web Design using JavaScript

Introduction - JavaScript including Techniques -


Variables and Operators - Conditional and Control
Statements - Data Types and Functions – Events - Form
Validation - Page Redirect - Java Script Exception
Handling - Document Object Model (DOM)

Java Script Exception Handling


4 16-11-2023

Course Outcomes:
CO. Outcome K Level

CO1 (Apply) Understand and apply HTML and CSS concepts K3

(Apply) Understand and apply JavaScript concepts for dynamic web page
CO2 K3
design

CO3 (Apply) Understand and apply shell commands and GIT workflow K2

CO4 (Apply) Design and develop mobile applications K3

CO5 (Apply) Design and develop mobile applications K2

Java Script Exception Handling


5 16-11-2023

Challenge time:
➢ Form Validation
➢ Page Redirect

Java Script Exception Handling


6 16-11-2023

Introduction:
➢ 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


7 16-11-2023

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


8 16-11-2023

Error Object:
➢ When a runtime error occurs, 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


9 16-11-2023

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


10 16-11-2023

JavaScript Errors Categorization (Cont..,):


➢ SyntaxError: An instance is created for the syntax error that may
occur 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


11 16-11-2023

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


12 16-11-2023

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


13 16-11-2023

catch{} statement:
➢ catch block handles the error of the code 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


14 16-11-2023

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


15 16-11-2023

Types of Exception Handling Statements:


➢ throw statements
➢ try…catch statements
➢ try…catch…finally statements.

Java Script Exception Handling


16 16-11-2023

Java Script Exception Handling


17 16-11-2023

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,
2012.
➢ Ultimate web design course: https://university.webflow.com/courses/ultimate-
web-design-course . Java Script Exception Handling
18 16-11-2023

Java Script Exception Handling


19 16-11-2023

Java Script Exception Handling

You might also like