Explanation of Solution
Given code:
The given code is highlighted below.
//Main Class
class Main
{
    //Main method
    public static void main(String[] args)
    {
//A variable is declared and a value is assigned
        int waitTime = 46;
        //Try block
        try
        {
            //Print the message
            System.out.println("Try block entered");
            //Check if value is greater than 30
            if(waitTime > 30)
                //Throw an exception
throw new Exception("Time Limit Exceeded.");
            //Print the message
System.out.println("Leaving try block.");
        }
        //Catch block
        catch (Exception e)
        {
            //Print the exception
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
- Suppose that statement2 causes an exception in the following statement: 1 try { 2 statement1; 3 statement2; 4 statement3;5 } 6 Catch (Exception ex1) 7 { 8 } 9 10 catch (Exception2 ex2) 11 { 12 throw ex2; 13 } 14 catch (Exception3 ex3) 15 { 16 } 17 finally { 18 statement4; } statement5;b. What will be the output the above mentioned code if we comment out the code from line 6 toline 16.iii. In square root if the value of number is negative throws IllegalArgumentException and of print message "square root is not possible". Create main class that display one normal execution of squareroot and one with exception case.   Subject: Java Programmingarrow_forwardJAVA Given a main program that searches for the ID or the name of a student from a text file, complete the findID() and the findName() methods that return the corresponding information of a student. Then, insert a try/catch statement in main() to catch any exceptions thrown by findID() or findName(), and output the exception message. Each line in the text file contains the name and the ID of a student, separated by a space. Method findID() takes two parameters, a student's name and a Scanner object containing the text file's contents. Method findID() returns the ID associated with the student's name if the name is in the file, otherwise the method throws an Exception object with the message "Student ID not found for studentName", where studentName is the name of the student. Method findName() takes two parameters, a student's ID and a Scanner object containing the text file's contents. Method findName() returns the name associated with the student's ID if the ID is in the file,…arrow_forwardWrite a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. (in Python)arrow_forward
- Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of…arrow_forwardPLZ help with the follwoing IN JAVA Suppose that statement2 causes an exception in the following try-catch block: Will statement3 be executed? If the exception is not caught, will statement4 be executed? If the exception is caught in the catch block, will statement4 be executed?arrow_forwardWrite a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError and output an exception message. Use another except block to catch any ValueError caused by invalid input and output an exception message. Note: ZeroDivisionError is thrown when a division by zero happens. ValueError is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of the program is: Input Exception: invalid literal for int() with base 10: '15.5'  My code: # Type your code here.user_num = input()div_num =…arrow_forward
- Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError and output an exception message. Use another except block to catch any ValueError caused by invalid input and output an exception message. Note: ZeroDivisionError is thrown when a division by zero happens. ValueError is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of the program is: Input Exception: invalid literal for int() with base 10: '15.5'  My code: # Type your code here.user_num = int(input())div_num =…arrow_forwardSuppose the exception class CrazyException is defined as follows: public class CrazyException extends Exception { public CrazyException() { super("Crazy exception thrown!"); System.out.println("Wow, Crazy exception thrown!"); } public CrazyException(String message) { super(message); System.out.println("Wow, crazy exception thrown with "+ "an argument!"); } public void crazyMethod() { System.out.println("Message is " + getMessage()); } } What output would be produced by the following unlikely code? CrazyException exceptionObject = new CrazyException(); System.out.println(exceptionObject.getMessage()); exceptionObject.crazyMethod();arrow_forwardWrite code that would create and handle a Divide by Zero exceptionarrow_forward
- Q#  When JUnit testing with exceptions, which of the following is true? Group of answer choices  A successful test happens whenever an exception is not thrown. Exceptions and tests should not be used together. A failed test results when you catch an exception on valid input. If you give an illegal argument to a method the JUnit test will fail.  Q#  When you want a method to return nothing, what do you put for the return type? Group of answer choices boolean false void null   Q#  Which of the following statements are true? Group of answer choices All of the options are true. Methods can take multiple primitives as arguments. Methods can take objects of other classes as arguments. A method for a class can take an object of that class as an argument.    Q#  What does Java guarantee is part of every class? Group of answer choices AtoString() A set of Getter methods to retrieve class variables. A method to get the binary representation of the class. A set of private class…arrow_forwardin java Write a program that reads integers userNum and divNum as input, and output the quotient (userNum divided by divNum). Use a try block to perform the statements. Use a catch block to catch any ArithmeticException and output an exception message with the getMessage() method. Use another catch block to catch any InputMismatchException and output an exception message with the toString() method. Note: ArithmeticException is thrown when a division by zero happens. InputMismatchException is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Arithmetic Exception: / by zero Ex: If the input of the program is: 15.5 5 the output of the program is: Input Mismatch Exception: java.util.InputMismatchException  LabProgram.java…arrow_forwardHas a catchphrase been used? What exactly does a finally clause mean? How do catch and finally operate in an exception program?arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning