Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 16.1, Problem 16.3CP

Explanation of Solution

Exception:

In C++, the exception is an object used to signal the unexpected error occurred during a program execution.

  • An exception has been thrown when an error has been occurred in a program.

Exception Handler:

The “throw point” is a statement which uses the keyword “throw” to throw an exception which occurred while executing the program.

  • After the execution of “throw” statement, the program control will move to another part in the same program to handle the exception is called as “exception handler”.
  • In order to handle an exception, construct a “try/catch” block in a program.

The “try” block:

  • The “try” block is starts with the keyword “try” and it contains the code which will have the possibility to generate an exception.
  • The “try” block must be followed by one or more “catch” blocks which are denoted as exception handlers.

The “catch” block:

  • The “catch” block is starts with the keyword “catch” and it is followed by an “exception parameter”.
  • The Catch block contains the code to be executed when the error occurred in Try block.

The general syntax for “try/catch” as follows:

try

{

//code which causes an exception;try block

}

Catch(Exception_argument)

{

//code which handles the exception;catch block

}

//Repeat catch blocks as many as needed

Multiple “catch” blocks:

In C++, a program can have multiple “catch” blocks for a single “try” block.

  • If program wants to test for several errors which may happen, then it should implement multiple “catch” blocks.
  • The “try” block must be followed by one or more “catch” blocks which are denoted as exception handlers...

Blurred answer
Students have asked these similar questions
I need help writing pseudocode for this function. The following pseudocode statement calls a function named half, which returns a value that is half that of the argument. (Assume both the result and number variables are Real.) Set result = half(number)
Need help converting my pseudocode to python, AND have a flowchart showing everything!The code:Main Module    Call InputModuleEnd Main Module Module InputModule    // This module gets input from the user    Declare Principal, AnnualRate, Years as Float     Output "Enter the Principal amount (P): "    Input Principal     Output "Enter the Annual Interest Rate (in percentage, e.g., 5 for 5%): "    Input AnnualRate     Output "Enter the number of Years to repay the loan: "    Input Years     Call DisplayPayment(Principal, AnnualRate, Years)End Module Module DisplayPayment(Principal, AnnualRate, Years)    // This module calculates and displays the monthly payment    Declare R, N as Float    Declare MonthlyPayment as Float    Declare PowerFactor as Float  // second local variable     // Calculate monthly interest rate R and number of months N    Set R = (AnnualRate / 100) / 12    Set N = Years * 12     // Calculate PowerFactor = (1 + R)^N    Set PowerFactor = (1 + R) ^ N     // Calculate…
Whats wrong with my pseudocode? Where did I make an error?Code:           Module main()                 Declare Real mileage                 Call getMileage()                 Display “You’ve drive a total of “, mileage, “ miles            End Module                       Module getMilage()                Display “Enter your mileage: “                 Input mileage            End Module

Chapter 16 Solutions

Starting Out with C++: Early Objects (9th Edition)

Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning