0% found this document useful (0 votes)
4 views3 pages

Coding Set 5 Exceptions

The document outlines a set of coding problems in Java focused on exception handling. It includes tasks such as handling division by zero, invalid array indices, non-numeric input, and creating custom exceptions. Each problem emphasizes different concepts of exception handling and validation in Java programming.

Uploaded by

sakshamkesar3
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)
4 views3 pages

Coding Set 5 Exceptions

The document outlines a set of coding problems in Java focused on exception handling. It includes tasks such as handling division by zero, invalid array indices, non-numeric input, and creating custom exceptions. Each problem emphasizes different concepts of exception handling and validation in Java programming.

Uploaded by

sakshamkesar3
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

Coding Problems in Java Programming by Tawqeer ul Islam

Coding Problems in Java – Set 5

1. Handle Division by Zero

Write a program that takes two integers and performs division. Handle the case where the
denominator is zero.

Concepts: try-catch, ArithmeticException

2. Handle Invalid Array Index

Create an array of size 5 and try to access an invalid index. Handle the exception gracefully.

Concepts: ArrayIndexOutOfBoundsException

3. Handle Non-Numeric Input

Take input from the user and convert it to an integer. Handle invalid (non-numeric) input.

Concepts: NumberFormatException

4. Multiple Catch Blocks

Write a program that:

• Takes two numbers as input (strings)

• Converts them to integers

• Divides them

Handle:

• Invalid number input

• Division by zero

Concepts: multiple catch blocks

5. File Reading with Exception Handling

Read data from a file. Handle file not found and ensure file is closed properly.

Concepts: IOException, finally


Coding Problems in Java Programming by Tawqeer ul Islam

6. Using finally Block

Write a program that demonstrates that finally always executes, even if an exception occurs.

Concepts: finally behavior

7. Throw Exception for Invalid Age

Create a method that accepts age. If age < 18, throw an exception with message "Not
eligible".

Concepts: throw, custom validation

8. Banking Withdrawal System

Simulate a bank account:

• If withdrawal amount > balance → throw exception

• Otherwise deduct amount

Concepts: logical exceptions, throw

9. Create Custom Exception

Create a custom exception class InvalidPasswordException.

Condition:

• Password must be at least 8 characters and contain a digit

Concepts: user-defined exceptions

10. Student Result Processing System

Create a system that:

• Accepts marks for 5 subjects

• Throws exception if marks < 0 or > 100

• Calculates average

• Handles all exceptions properly

Concepts:

• validation

• multiple exceptions
Coding Problems in Java Programming by Tawqeer ul Islam

• clean program structure

Bonus Challenge

11. Nested Exception Handling

Write a program with:

• inner try-catch inside outer try-catch

• demonstrate how control flows

You might also like