Write a program that uses an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. You will create the StringTooLongException.java file first based on the information presented in the chapter. In the StringError.java program, read strings from the user until the user enters "DONE". If a string is entered that has too many characters (say 10), throw the exception. StringError should catch and handle the exception if it is thrown. Handle the exception by printing an appropriate message, and then continue processing more strings.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter12: Exception Handling
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

Write a program that uses an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it.  You will create the StringTooLongException.java file first based on the information presented in the chapter.

In the StringError.java program, read strings from the user until the user enters "DONE".

If a string is entered that has too many characters (say 10), throw the exception. StringError should catch and handle the exception if it is thrown. Handle the exception by printing an appropriate message, and then continue processing more strings.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Custom Exception class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning