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

Unit-4-Exception-Handling

The document discusses exception handling in Java, including defining exceptions, using try...catch blocks, and implementing finally blocks. It provides examples of handling division by zero errors and outlines a practical activity for developing a Billing System that manages user input errors. The activity emphasizes the importance of graceful error management and includes specific error messages for invalid inputs and insufficient payments.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Unit-4-Exception-Handling

The document discusses exception handling in Java, including defining exceptions, using try...catch blocks, and implementing finally blocks. It provides examples of handling division by zero errors and outlines a practical activity for developing a Billing System that manages user input errors. The activity emphasizes the importance of graceful error management and includes specific error messages for invalid inputs and insufficient payments.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

PRINCE MERT O.

NICOLAS
NEUST
At the end of the discussion, we shall be able to;
• Define exceptions;
• Use try…catch block
• Implement finally block
• Integrate throw and throws exception
An exception is an event, which occurs
during the execution of a program, that
disrupts the normal flow of the program's
instructions.
Exception handling is a core concept in
Java, allowing developers to manage
errors gracefully and maintain the flow of
a program even when unexpected
situations occur.
Create a class that divides a number by zero. Write
a try…catch block to catch the error that may
occur.

Sample computation:
int i = 56/0;
Create a class that divides a number by zero. Write
a specific try…catch block to catch the error that
may occur.

Sample computation:
int i = 56/0;
Write a try…catch block for the specific
exception and display “This isn’t possible!”.
Fill in the blanks. Supply all the missing code in the block.
Fill in the blanks. Supply all the missing code in the block.
Activity 1
You are developing a Billing System for a grocery
store. The system should allow the cashier to enter the
total amount and the amount paid by the customer.
The program should then calculate the change.
However, the following conditions must be handled using a try-catch block:
• If the cashier enters a non-numeric value for the total amount or amount
paid, the program should display:
"Invalid input! Please enter a numeric value."
• If the amount paid is less than the total amount, the program should
display:
"Insufficient payment! Please ask the customer for the correct amount.“
• Use the finally block to print “Exception successfully handled”

You might also like