Java Practice Exercise – Exception Handling

  • Write a java program that illustrates the following
    • Handling predefined exceptions.
    • Handling user defined exceptions
  • Write a Java program for handling the following exceptions
    • Arithmetic Exception
    • ArrayIndexOutOfBounds Exception
    • NumberFormat Exception
    • StringIndexOutOfBound Exception
  • Write a Java program to implement user defined exception handling
  • Write an exception class for a time of day that can accept only 24 hour representation of clock hours. Write a java program to input various formats of timings and throw suitable error messages
  • Write a java program for exception handling:
    • To create a user defined exception whenever user input the word “hello”.
    • To add two integers and raise exception when any other character except number (0 – 9) is given as input
  • Create a class Doctor with attributes id, name, age and department. Initialize values through parameterized constructor. If age of Doctor is not in between 25 and 65 then generate user-defined exception “AgeNotWithinRangeException”. If name contains numbers or special symbols raise exception “NameNotValidException”. Define the two exception classes
  • A program accepts two integers as command line arguments. It displays all prime numbers between these two. Validate the input for the following criteria: Both should be positive integers. The second should be larger than the first. Create user defined exceptions for both