Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 9.2, Problem 16STQ
Program Plan Intro

Program plan:

  • • Create a class named “MessageTooLongException” that extends “Exception”.
    • ○ Define a default constructor that calls the parent class’s method using “super ()” by passing a message.
    • ○ Define a parameterized constructor that calls the parent class’s method using “super ()” by passing a message that is given as the argument.
  • • Create a class named “Main”.
    • ○ Define the “main ()” method.
      • ■ Create an object “e” for the class. Here the exception is thrown using default constructor.
      • ■ Get and print the message using the method “e.getMessage()”.

Blurred answer
Students have asked these similar questions
I want to throw an IllegalArgumentException type exception in my code even if it does not arise on its own. Provide a line of code that could instantiate and throw such exception. Make sure to provide a complete compilable line of code, including the semicolon.
In Java Create a class for a runtime exception called InvalidRangeException. Then, re-write the constructor for the Airplane class so that it throws the InvalidRangeException if the range is a negative number.
Write a class called MyException with appropriate attributes and methods toprocess different types of exceptions thrown in C++ and add proper comments in the code.thanks

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning