Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134521176
Author: SAVITCH
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 16.1, Problem 4STE

What happens when a throw statement is executed? This is a general question. Tell what happens in general, not simply what happens in the code in Self-Test Question 1 or some other sample code.

1. What output is produced by the following code?

int waitTime = 46;

try

{

cout << "Try block entered.\n";

if (waitTime > 30)

throw waitTime;

cout << "Leaving try block.\n";

}

catch(int thrownValue)

{

cout << "Exception thrown with\n"

<< "waitTime equal to " << thrownValue << endl;

}

cout << "After catch block." << endl;

Blurred answer
Students have asked these similar questions
Solve In Python Provide Screenshots of Input and Ouput For this lab, you will modify your Lab 7 to make several improvements to the getter/settermethods. Instead of having them return True/False, modify each one to throw an exception ifinvalid data is passed.Modify these methods in the following way:• add_hours()o If the number of hours being added is less than 0, throw an exception• add_sales()o If the amount of sales being added is less than 0, throw an exception• set_employee_number()o The employee number must be an integer. If the given input is not an integer,throw an exception• set_office_number()o If the office number given is less than 100 or greater than 500, throw anexception.• set_name()o If the given name is empty, throw an exceptiono Any of the following characters should be removed from the name: ‘_’, ‘.’, ‘-‘ (Underscore, period, and dash)• set_birthdate()o If the given value for the month is less than 1 or greater than 12, throw anexceptiono If the given value for the…
I have a question about the following code, why do they have different output, please explain to me.  class Test { private:   int x;   int y; public:   Test(int x = 0, int y = 0) { this->x = x; this->y = y; }   Test &setX(int a) { x = a; return *this; }   Test &setY(int b) { y = b; return *this; }   void print() { cout << "x = " << x << " y = " << y << endl; } };    int main() {   Test obj1(5, 5);      // Chained function calls.  All calls modify the same object   // as the same object is returned by reference   obj1.setX(10).setY(20);      obj1.print();   return 0; }   #include<iostream> using namespace std;    class Test { private:   int x;   int y; public:   Test (int x = 0, int y = 0) { this->x = x; this->y = y; }   Test setX(int a) { x = a; return *this; }   Test setY(int b) { y = b; return *this; }   void print() { cout << "x = " << x << " y = " << y << endl; } };    int main() {   Test obj1;…
What is the difference between using @Test(expected = TypeOfException) and using try/catch when testing if a method or constructor properly returns an exception? A. They do the same thing.   B. @Test(expected = ...) is the proper way to unit test in java, and try/catch should only be used when unit testing in Python.   C. @Test(expected = ...) will give a passing test as soon as one exception of the proper type is thrown and then stop the test, but using try/catch will allow you to test many examples in the same test and will only stop after running all examples or reaching a fail() or an assert statement that fails.   D. We should never use try/catch when unit testing, otherwise we will catch the exception and then won't know if it is actually thrown.
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License