Professional Documents
Culture Documents
MODULE 8
Computer Programming (Java) – Grade 12
Quarter 3 – Module 8: Throw and Throws Statements in Java
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.
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:
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:
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.
Posttest - This measure how much you have learned from the
entire module.
EXPECTATIONS
PRETEST
RECAP
DIRECTIONS: On the space provided, discuss and enumerate what you have learned
from the previous lesson.
LESSON
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 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.
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
WRAP-UP
From the previous activity, In your own understanding of the lesson, kindly answer
the following questions:
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
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/