You are on page 1of 10

QUARTER 3

MODULE 8
Computer Programming (Java) – Grade 12
Quarter 3 – Module 8: Throw and Throws Statements in Java

First Edition, 2020

Republic Act 8293, Section 176 states that no copyright shall subsist in any
work of the Government of the Philippines. However, prior approval of the
government agency or office wherein the work is created shall be necessary for
exploitation of such work for profit. Such agency or office may, among other things,
impose as a condition the payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand


names, trademarks, etc.) included in this module are owned by their respective
copyright holders. Every effort has been exerted to locate and seek permission to use
these materials from their respective copyright owners. The publisher and authors
do not represent nor claim ownership over them.

Published by the Department of Education - Schools Division of Pasig City

Development Team of the Self-Learning Module


Writer: Paola T. Galario
Editor: Mrs. Lerma O. Cantanero
Reviewers: Mrs. Rowena O. Dimagiba
Illustrator:
Layout Artist:
Management Team: Ma. Evalou Concepcion A. Agustin
OIC-Schools Division Superintendent
Aurelio G. Alfonso EdD
OIC-Assistant Schools Division Superintendent
Victor M. Javeña EdD
Chief, School Governance and Operations Division and
OIC-Chief, Curriculum Implementation Division

Education Program Supervisors

Librada L. Agon EdD (EPP/TLE/TVL/TVE)


Liza A. Alvarez (Science/STEM/SSP)
Bernard R. Balitao (AP/HUMSS)
Joselito E. Calios (English/SPFL/GAS)
Norlyn D. Conde EdD (MAPEH/SPA/SPS/HOPE/A&D/Sports)
Wilma Q. Del Rosario (LRMS/ADM)
Ma. Teresita E. Herrera EdD (Filipino/GAS/Piling Larang)
Perlita M. Ignacio PhD (EsP)
Dulce O. Santos PhD (Kindergarten/MTB-MLE)
Teresita P. Tagulao EdD (Mathematics/ABM)

Printed in the Philippines by Department of Education – Schools Division of


Pasig City
Computer
Programming
QUARTER 3
+
MODULE

8 Throw and Throws Statements


in Java

Writer : Paola T. Galario


Editor : Mrs. Lerma O. Cantanero
Reviewers : Mrs. Rowena O. Dimagiba
Introductory Message

For the Facilitator:

Welcome to the Computer Programming (Java) 12 Self-Learning Module on


Throw and Throws Statements in Java!

This Self-Learning Module was collaboratively designed, developed and


reviewed by educators from the Schools Division Office of Pasig City headed by its
Officer-in-Charge Schools Division Superintendent, Ma. Evalou Concepcion A.
Agustin, in partnership with the City Government of Pasig through its mayor,
Honorable Victor Ma. Regis N. Sotto. The writers utilized the standards set by the K
to 12 Curriculum using the Most Essential Learning Competencies (MELC) in
developing this instructional resource.

This learning material hopes to engage the learners in guided and independent
learning activities at their own pace and time. Further, this also aims to help learners
acquire the needed 21st century skills especially the 5 Cs, namely: Communication,
Collaboration, Creativity, Critical Thinking, and Character while taking into
consideration their needs and circumstances.

In addition to the material in the main text, you will also see this box in the
body of the module:

Notes to the Teacher


This contains helpful tips or strategies that
will help you in guiding the learners.

As a facilitator you are expected to orient the learners on how to use this
module. You also need to keep track of the learners' progress while allowing them to
manage their own learning. Moreover, you are expected to encourage and assist the
learners as they do the tasks included in the module.
For the Learner:

Welcome to the Computer Programming (Java) 12 Self-Learning Module on


Throw and Throws Statements in Java!

This module was designed to provide you with fun and meaningful
opportunities for guided and independent learning at your own pace and time. You
will be enabled to process the contents of the learning material while being an active
learner.

This module has the following parts and corresponding icons:

Expectations - This points to the set of knowledge and skills


that you will learn after completing the module.

Pretest - This measures your prior knowledge about the lesson


at hand.

Recap - This part of the module provides a review of concepts


and skills that you already know about a previous lesson.

Lesson - This section discusses the topic in the module.

Activities - This is a set of activities that you need to perform.

Wrap-Up - This section summarizes the concepts and


application of the lesson.

Valuing - This part integrates a desirable moral value in the


lesson.

Posttest - This measure how much you have learned from the
entire module.
EXPECTATIONS

After completing this lesson, you should be able to:

1. describe the Throw and Throws Statements in Java,


2. understand the importance of Throw and Throws Statements in coding,
and
3. apply the concept of Throw and Throws Statements in accordance to
Java framework.

PRETEST

The K-W-L CHART


DIRECTIONS: Before we begin on our topic. Complete the table below by listing
down everything you know about “Throw and Throws Statements in Java.”

What I know What I want to Know What I learned

RECAP
DIRECTIONS: On the space provided, discuss and enumerate what you have learned
from the previous lesson.
LESSON

Throw and Throws Statements

The Throw keyword is used to create a custom error. The throw statement is
used together with an exception type. There are many exception types available in
Java: ArithmeticException, ClassNotFoundException, ArrayIndexOutOfBoundsExce
ptions, SecurityException, etc. The exception type is often used together with a
custom method.

Throws is a keyword in Java which is used in the signature of method to


indicate that this method might throw one of the listed type exceptions. The caller to
these methods has to handle the exception using a try-catch block.

Important points to remember about throws keyword:

• throws keyword is required only for checked exception and usage of throws
keyword for unchecked exception is meaningless.
• throws keyword is required only to convince compiler and usage of throws
keyword does not prevent abnormal termination of program.
• By the help of throws keyword we can provide information to the caller of the
method about the exception.

The following are difference between throw and throws:

Throw Throws
Used to throw an exception for a method Used to indicate what exception type
may be thrown by a method
Cannot throw multiple exceptions Can declare multiple exceptions
Syntax:
Syntax:
• throw is followed by an object
(new type) • throws is followed by a class
• used inside the method • and used with the method
signature
ACTIVITIES

DIRECTIONS: Create a simple code/program that would output at 4 different Types


of Throw Exception that returns message of “This is the error message”. Put the
answer in “// Insert the Throw Exception here” and use the template below in the compiler.

public class Main


{
public static void main(String[] args) {
try {
// Insert the Throw Exception here. 
}
catch (Exception exp) {
System.out.println("Error: "+exp.getMessage());
}
}
}
RUBRICS:
10 8 5 1
The program The program The program The program
showed at least 4 showed at least 3 showed at least 2 showed at least 1
different Throw different Throw different Throw different Throw
Exception that Exception that Exception that Exception that
returns “This is returns “This is returns “This is returns “This is
the error message” the error message” the error message” the error
message”

WRAP-UP

From the previous activity, In your own understanding of the lesson, kindly answer
the following questions:

1. What do we mean by throw and throw statements?


_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
2. What are the purpose of throw and throws statements in your Java program?
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
VALUING

DIRECTIONS: Answer the following questions below, and write your answer in the
space provided.

1. Based on what you have learned in this lesson, what do you think is the benefit
and importance of throw and throws statements in your program? Do you think
it’s a big help for your program become easier? Why?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

POST-TEST

DIRECTIONS: Identify the following word/s to complete each sentences.

1. ____________ is followed by a class.


2. The Throw keyword is used to create an __________ error.
3. The exception type is often used together with a custom ___________.
4. Throws can declare ____________ exceptions.
5. The __________ keyword is used to explicitly throw a single exception.
KEY TO CORRECTION

5. Throw
4. Multiple
3. Method
2. Custom
1. Throws
POST TEST

References
Websites:
Difference between Throw and Throws in Java, Accessed February 3, 2021,
09:10:01 AM, https://beginnersbook.com/2013/04/difference-between-throw-
and-throws-in-java/

Throw and Throws in Java, Accessed February 3, 2021, 11:03:34 AM,


https://www.geeksforgeeks.org/throw-throws-java/

Java Throw keyword, Accessed February 3, 2021, 03:12:40 PM,,


https://javarevisited.blogspot.com/2018/07/10-object-oriented-design-
principles.html

Java Throw and Throws, Accessed February 3, 2021, 04:30:01 PM,,


https://www.programiz.com/java-programming/throw-throws

You might also like