Java Exception Handling - Exercises, Practices, Solutions
This resource offers a total of 35 Java handling and managing exceptions problems for practice. It includes 7 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
[An Editor is available at the bottom of the page to write and execute the scripts.]
Java Exceptions to handle errors:
Java programming language uses exceptions to handle errors and other exceptional events. An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.
This section covers how to catch and handle exceptions. It includes try, catch, and finally block, as well as chained exceptions and logging exercises.
1. Throw and Catch Exception with Try-Catch
Write a Java program that throws an exception and catch it using a try-catch block.
2. Throw Exception for Odd Number
Write a Java program to create a method that takes an integer as a parameter and throws an exception if the number is odd.
3. Throw Exception if File Not Found
Write a Java program to create a method that reads a file and throws an exception if the file is not found.
4. Throw Exception for Positive Numbers in File
Write a Java program that reads a list of numbers from a file and throws an exception if any of the numbers are positive.
5. Throw Exception if File is Empty
Write a Java program that reads a file and throws an exception if the file is empty.
6. Throw Exception for Duplicate Integers
Write a Java program that reads a list of integers from the user and throws an exception if any numbers are duplicates.
7. Throw Exception if String Has No Vowels
Write a Java program to create a method that takes a string as input and throws an exception if the string does not contain vowels.
Java Code Editor
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.