Lab 2 (Exception)

Create a custom exception class MyCustomException

  • Create a class MyCustomException that inherits from Exception class
  • Define a Constructor class that takes string as an argument
  • Call a super class that takes the string argument inside the constructor;
  • Write a method name divideInt(int i, int j) that takes two arguments and perform the division of two numbers and throws MyCustomException
  • Define a Constructor class that takes two arguments string and Throwable as an argument
  • Call a super class constructor that takes string and Throwable as an arguments
  • Write a method arrayOutOfBound() which calculate the arrayoutofbound exception on catch method use MyCustomException constructor which takes two arguments string and Throwable
  • Create and object of ArrayIndexOutofBoundException and call the method initCause() and print the result.
  • On main method
  • Wrap your code inside try catch and finally block
  • Define a integer variable result that will call the divideInt method
  • Pass the valid numbers inside the method for e.g (10,5)
  • print the message that displays 10 divided by 5 = result
  • pass the invalid number inside the method for e.g (10,0)
  • print the message using MyCustomException class Constructor which takes two arguments
  • call the arrayOutOfBound() method and print the exception
  • Follow the examples JavaCustomExceptionExample.java and Exception.java for the reference
  • Expected output
  • Due Date : 6/12/2023 12:00 PM

    How to submit lab?

  • Add your full name and email at the top of the file using a comment tag.
  • Compile and run your program, entering the required inputs.
  • Take a screenshot of the result.
  • Zip your project with the source code, then upload it on Blackboard.
  • Upload screenshot on Blackboard.
  • Note: Submit the assignment on Blackboard by the due date. Email and late submissions will not be accepted.