Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
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
Why using catch (exception) is always a bad idea?
What happens when a catch block throws an Exception?
What is the catch phrase?  What is a finally clause?   How do both catch and finally work in an exception program?

Chapter 16 Solutions

Starting Out With C++: Early Objects, Student Value Edition (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.
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,