C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
Question
Book Icon
Chapter 17, Problem 17.30E
Program Plan Intro

Program Plan:

  • Include header files required
  • Declare and define a function test().
  • Start a try block.
    • Accept a choice to enter a number or a character.
    • If 1 is entered as choice, a number is accepted and checked if it’s a negative number.
    • If a negative number then and throw an exception with integer parameter, which is caught from main function.
    • If 2 is entered as choice, a character is accepted and checked if it is zero. If Zero, then throw an exception with character parameter, which is caught from inside function.
    • Write a catch block with character parameter which will display exception with character.
    • End of function.
  • Start a main function
    • Start a try block which will call a function "test()", that will throw an exception.
    • Write a catch block with integer parameter which will display exception called.
  • Return and exit main.

Blurred answer
Students have asked these similar questions
(Stack Unwinding) Write a program that throws an exception from a deeply nested function and still has the catch handler following the try block enclosing the initial call in main catchthe exception.
(Local Variable Destructors) Write a program illustrating that all destructors for objectsconstructed in a block are called before an exception is thrown from that block.
(Throwing Exceptions from a catch) Suppose a program throws an exception and the appropriate exception handler begins executing. Now suppose that the exception handler itself throwsthe same exception. Does this create infinite recursion? Write a program to check your observation.
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