Answered step by step
Verified Expert Solution
Question
1 Approved Answer
An exception is an abnormal condition that arises in a code sequence at run time. Java provides powerful features for exception handling. Although Java's
An exception is an abnormal condition that arises in a code sequence at run time. Java provides powerful features for exception handling. Although Java's built-in exceptions handle most common exceptions, you will probably want to create your own exception types to handle situations specific to your applications. This is quite easy to do: just define a subclass of Exception. Consider the following practical example where a user defined exception subclass has been designed and used for taking marks data input. An object of the user defined exception subclass InvalidMarks Exception has been thrown when the given marks is found to be invalid, ie, greater than 100 or less than 0. Obviously, this example has been used to demonstrate, and you cannot use this as your solution. Your task will be to design and apply your own exception subclass. The designed exception subclass and its use must be practical (ie., resemble with real-life) as like the given example. Take care of the followings: L Design one class as your own exception subclass (ie, which extends the Exception class). Use at least one variable, one parameterized constructor and a toString method inside the subclass. I Design another class and the main method inside at Inside this class, apply your designed exception for a practical need as explained in the following example. Submission Format: Submit your java program file. import java.util.Scanner; class Invalid MarksException extends Exception{ int marks; InvalidMarksException(int a){ } marks a; public String toString(){ return "InvalidMarksException: "+marks; > public class MyExcepEx ( static void compute(int marks) throws InvalidMarksException { if(marks 100 || marks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started