Give the minimum code necessary to define an unchecked excep

Give the minimum code necessary to define an unchecked exception class called IllegalIntegerException.

Give all the code to throw an exception object in the class: IllegalIntegerException.

Solution

Please follow the code and comments for description :

CODE :

class IllegalIntegerException extends RuntimeException { // class that extends the runtime exception class

IllegalIntegerException(String s) { // defining the exception
super(s); // call the super class
}

}

public class RunTimeUserDefExcepTest { // class to run the code

public static void main(String[] arg) { // driver method
try { // try catch code
throw new IllegalIntegerException(\"The User Defined Unchecked Exception was thrown and handled.\"); // throw and exception defined
} catch (IllegalIntegerException e) { // catch the exception
e.printStackTrace(); // print to console
}

}
}


OUTPUT :

com.abc.IllegalIntegerException: The User Defined Unchecked Exception was thrown and handled.
   at chegg_new.RunTimeUserDefExcepTest.main(RunTimeUserDefExcepTest.java:24)
  
  
Hope this is helpful.

Give the minimum code necessary to define an unchecked exception class called IllegalIntegerException. Give all the code to throw an exception object in the cla

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site