234,281 views
10 votes
10 votes
Modify the solution to PP 11.1 such that it catches and handles the exception if it is thrown. Handle the exception by printing an appropriate message, and then continue processing more strings.

User Clash
by
2.9k points

1 Answer

9 votes
9 votes

Answer:

Step-by-step explanation:

The following code is written in Java. After finding the PP 11.1 file online I added the try/catch to the code as requested by the question. The program takes the input from the user, checks it's length, and if it contains more than 20 characters it throws the exception. This exception states that "the string has more than 20 characters" and then continues processing more strings until the user enters "DONE". The program has been tested and the output can be seen in the attached image below. Due to technical difficulties I have added the code as a txt file below.

Modify the solution to PP 11.1 such that it catches and handles the exception if it-example-1
User Majd Albaho
by
3.0k points