Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 16.1, Problem 6STE
Program Plan Intro
Exception:
An exception is a problem that creates during the execution of a program; it offers a method to transfer control from one part to another part of a program.
An exception handling is created by using the following three keywords such as try, catch and throw.
- The “try” block have the program for the basic
algorithm that says the computer what to do when all goes well. - The “throw” keyword throws an error statement to the “catch” block.
- The “catch” block will catch the exception or handling the exception.
Generally, the compiler executes “try” block. In the “try” block, if the statements cause an exception, it throws an error statement to the “catch” block using the keyword “throw”. The “catch” block then handles the error based upon the type of exception.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Consider the following code:
public static void test_b(int n)
{
if (n>0)
test_b(n-2);
System.out.println(n + " ");
}
What is printed by the call test_b(6)?
Consider the following code:
public static void test_a(int n) { System.out.println(n + " "); if (n>0) test_a(n-2); }What is printed by the call test_a(6)?
2- Trace the following code and write the output:
class Test1 {
Test1(int x)
{
System.out.println("Test Calls " + x);
class
Test2 {
Testi t1 = new Test1(10);
Test2(int i) { t1 = new Test1(i); }
public static void main(String[]
args)
{
Test2 t2 = new Test2(5);
Chapter 16 Solutions
Problem Solving with C++ (9th Edition)
Ch. 16.1 - Prob. 1STECh. 16.1 - What would be the output produced by the code in...Ch. 16.1 - Prob. 3STECh. 16.1 - What happens when a throw statement is executed?...Ch. 16.1 - In the code given in Self-Test Exercise 1, what is...Ch. 16.1 - Prob. 6STECh. 16.1 - Prob. 7STECh. 16.1 - What is the output produced by the following...Ch. 16.1 - What is the output produced by the program in...Ch. 16.2 - Prob. 10STE
Knowledge Booster
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
- this practice assignment wants me to : Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd. it is saying that i am missing a return statement. here is my code: mport java.util.Scanner; class EvenOdd { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number; System.out.println("Enter the integer >>>"); number = input.nextInt(); } public static boolean isEven(int number) { if (number % 2 == 0) System.out.println("The number is even."); else System.out.println("The number is odd."); } }arrow_forwardFor Java Write code for an if-else block that checks separates integers into the following categories: An integer less than 0, An integer greater than 0 and less than or equal to 10, An integer greater than 10 that is even, and an integer greater than 10 that is odd. Have each category print out a different statement. What are some ways you can make your code more efficient when using if-else blocks?arrow_forwardPROBLEM: I need to make an ATM program that allows the user to check his or her balance after entering his or her correct PIN and the maintaining balance is Php 8000. A message is shown when the balance is below PHP 8,000 for withdrawal and its remaining balance. Another message is shown when the balance is PHP 8,000 and above for deposit and its updated balance. The code: import random import sys class ATM(): def __init__(self, name, account_number, balance = 0): self.name = name self.account_number = account_number self.balance = balance def account_detail(self): print("\n----------ACCOUNT DETAIL----------") print(f"Account Holder: {self.name.upper()}") print(f"Account Number: {self.account_number}") print(f"Available balance: Nu.{self.balance}\n") def deposit(self, amount): self.amount = amount self.balance = self.balance + self.amount print("Current account…arrow_forward
- Assume that the SampleQueue class, with the given code below, is used in the TestSampleQueue that is also shown below. Show the output of the TestSampleQueue. Do the exercise without using a computer (i.e. Make amanual trace of the program):// TestSampleQueue classimport java.io.*;import java.lang.*;public class TestSampleQueue {private SampleQueue<Integer> queue = new SampleQueue<Integer>();public void run() throws Exception {queue.enqueue(new Integer(10));System.out.println(queue.toString());queue.enqueue(new Integer(5));System.out.println(queue.toString());queue.dequeue();System.out.println(queue.toString());queue.enqueue(new Integer(15));System.out.println(queue.toString());queue.enqueue(new Integer(7));System.out.println(queue.toString());queue.dequeue();System.out.println(queue.toString());} // end of run methodpublic static void main(String[] args) {TestSampleQueue program;try {program = new TestSampleQueue();program.run();} catch ( Exception e )…arrow_forwardi need help with codingarrow_forwardAnalyze the following code: public class Test{ public static void main(String[] args) { try { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException } } catch (Exception ex) { System.out.println("NumberFormatException"); int i = 0; int y = 2/i; } catch (RuntimeException ex) { } } System.out.println("RuntimeException"); The program displays NumberFormatException. The program displays RuntimeException. The program displays NumberFormatException followed by RuntimeException. The program has a compile error.arrow_forward
- In Kotlin, Write code that declares a nullable Int and sets its value, then declares a nullable Double and uses the safe call operator to sets its value to null if the nullable Int was null, else to the result of casting the Int to a Double. Write code that that declares a nullable Int and sets its value, then declares a nullable Double and uses the safe call operator and the Elvis operator to sets its value to 0.0 if the nullable Int was null, else to the result of casting the Int to a Double.arrow_forwardPF Assignment 3 BS ERP 105903 Submission date: 18th April, 2021 via LMS Assignment should include:Hand Wriiten Coding + Screenshot of Output (a) Create a method GetMax() which takes two integer (int) parameters as an arguments and returns maximal of the two numbers. (b) Write a program that reads three numbers from the console and prints the biggest of them. Use the GetMax() method you just created. Write a test program that validates that the methods works correctly. Write a method that returns the digits of a given decimal number in a reversed order. For example 256, must be printed as 652. Write a program in C to check a given number is positive or negative using method. Write a program that calculates and prints the n! for any n in the range [1…10] number should be taken as input from user through main and should pass as an argument to the method. Write a program in C# Sharp to create a function to input a string and return count of number of spaces are in the…arrow_forwardIf integer yearInHistory is 1815, output "Battle of Waterloo. Otherwise, output "Not battle of Waterloo End with a newline. Ex: If the input is 1815, then the output is: Battle of Waterloo 1 import java.util.Scanner; 2 3 public class IfElse ( 4 public static void main(String[] args) { 5 90423 10 11 12 ) 13 Scanner schr- new Scanner(System.in); int yearInHistory; year InHistory - scor.nextInt (); y Your code goes here /arrow_forward
- How to develop a test from this code using JUNIT test code? package stubdriver; public class Driver1{public static void main(String[] args){double converted, original;int i, j;String from, to;String[] units = {"inches","feet","yards","miles"};UnitConverter1 calculator; calculator = new UnitConverter1(); original = 10.0;for (i=0; i < units.length; i++) {for (j=0; j < units.length; j++) { from = units[i]; // This could be outside the inner loopto = units[j];converted = calculator.convert(original, from, to);System.out.println(original+" "+from+" = "+converted+" "+to);}}} }arrow_forwardUse the following code to answer the question public class SpeedTrap {private int speedLimit;/*** Creates a new SpeedTrap with the given* speed limit* * @precondition speedLimit >= 1* @postcondition getSpeedLimit()==speedLimit*/public SpeedTrap(int speedLimit) {if (speedLimit < 1) {throw new IllegalArgumentException("invalid speed limit");}this.speedLimit = speedLimit;}/*** Gets the speed limit* @return the speed limit*/public int getSpeedLimit() {return this.speedLimit;}/*** Checks to see if the given miles-per-hour* is considered speeding.** @precondition mph >= 0* @postcondition none** @returns true if speeding; false otherwise*/public boolean isSpeeding(int mph) {if (mph < 0) {throw new IllegalArgumentException("invalid mph");}return (mph > this.speedLimit);}}Write a JUnit test named testWhenSpeeding that uses a value for mph that is valid and is considered speeding.arrow_forwardUse the following code to answer the question public class SpeedTrap {private int speedLimit;/*** Creates a new SpeedTrap with the given* speed limit* * @precondition speedLimit >= 1* @postcondition getSpeedLimit()==speedLimit*/public SpeedTrap(int speedLimit) {if (speedLimit < 1) {throw new IllegalArgumentException("invalid speed limit");}this.speedLimit = speedLimit;}/*** Gets the speed limit* @return the speed limit*/public int getSpeedLimit() {return this.speedLimit;}/*** Checks to see if the given miles-per-hour* is considered speeding.** @precondition mph >= 0* @postcondition none** @returns true if speeding; false otherwise*/public boolean isSpeeding(int mph) {if (mph < 0) {throw new IllegalArgumentException("invalid mph");}return (mph > this.speedLimit);}}Write a JUnit test for the SpeedTrap constructor named testWhenOneUnderSpeedLimitBoundaryarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License