Question

In: Computer Science

Exception handling All Exceptions that can be thrown must descend from this Java class: The getMessage(...

Exception handling

All Exceptions that can be thrown must descend from this Java class:

The getMessage( ) method is inherited from this class?

What are the two broad catagories of Exceptions in Java?

If an Exception is not a checked exception it must extend what class?

What is the difference between a checked Exception and an unchecked Exception?

What are the two options a programmer has when writing code that may cause a checked Exception to be thrown? Can a try block contain code that would cause more than one type of Exception to possibly be thrown?

Is it true that a try block can only be followed by ONE catch block?

What is the purpose of the finally block?

When is the code in the finally block executed?

What happens when a try block throws an Exception object? Is an Exception the same thing as a syntax or logic error?

Solutions

Expert Solution

ANSWER:-

-> getMessage() is a method of Throwable class which is inherited by every exception class like ArithmeticException,NullpointerException etc.

-> There are two categories of exceptions

   1.checked exception

   2.unchecked exception

-> If an exception is not checked exception then it must extend RuntimeException class.

->Difference between checked and unchecked exceptions:-

   1. Checked Exception:- The classes which extend Throwable class except RuntimeException,those exceptions are known as checked exceptions. These exceptions checked at compile time.

    2.Unchecked Exceptions:- The classes which extend RuntimeException class ,those are known as unchecked exceptions. These are checked at runtime.

->A programmer has two options. Those are:

1. Using throws keyword ,a programmer can throw an exception

2. try-catch block

A try block can contain more than one exception that can be thrown by catch blocks.

-> A try bock can contain multiple catch blocks.

try{

     //code

}catch(//exception parameter){

     //code

}

catch(//exception parameter){

    //code

}

catch(//exception parameter){

    //code

}

-> finally block executes irrespective of the exception that means even if exception occurs or not finally block must excecute.

-> When an exception is thrown it checks whether catch block regarding that exception is there or not. if it is there, the code in the catch block executes. if it is not there,then it shows default error message.

     THANK YOU!!!!!


Related Solutions

*In Java please! EXCEPTION HANDLING Concept Summary: 1. Exception   handling   2. Class   design Description Write   a  ...
*In Java please! EXCEPTION HANDLING Concept Summary: 1. Exception   handling   2. Class   design Description Write   a   program   that   creates   an   exception   class   called   ManyCharactersException,   designed   to   be   thrown   when   a   string   is   discovered   that   has   too   many   characters   in   it. Consider   a   program   that   takes   in   the   last   names   of   users.   The   driver   class   of   the   program reads the   names   (strings) from   the   user   until   the   user   enters   "DONE".   If   a   name is   entered   that   has   more   than   20   characters,  ...
EXCEPTION HANDLING Concept Summary: 1. Exception handling 2. Class design Description Write a program that creates...
EXCEPTION HANDLING Concept Summary: 1. Exception handling 2. Class design Description Write a program that creates an exception class called ManyCharactersException, designed to be thrown when a string is discovered that has too many characters in it. Consider a program that takes in the last names of users. The driver class of the program reads the names (strings) from the user until the user enters "DONE". If a name is entered that has more than 20 characters, throw the exception....
EXCEPTION HANDLING Concept Summary: 1. Exception   handling   2. Class   design Description Write   a   program   that   creates  ...
EXCEPTION HANDLING Concept Summary: 1. Exception   handling   2. Class   design Description Write   a   program   that   creates   an   exception   class   called   ManyCharactersException,   designed   to be thrown when a   string is discovered that has too many characters in it. Consider a   program that   takes   in the last   names   of   users.   The   driver   class   of   the   program reads the   names   (strings) from   the   user   until   the   user   enters   "DONE".   If   a   name is   entered   that   has   more   than   20   characters,   throw   the   exception.  ...
Create a java program that: - Has a class that defines an exception -Have that exception...
Create a java program that: - Has a class that defines an exception -Have that exception throw(n) in one method, and be caught and handled in another one. -Has a program that always continues even if incorrect data is entered by the user -has a minimum of 2 classes in it
c++ Add exception handling to the MyStack class (e.g. an instance of the class should throw...
c++ Add exception handling to the MyStack class (e.g. an instance of the class should throw an exception if an attempt is made to remove a value from an empty stack) and use the MyStack class to measure the execution cost of throwing an exception. Create an empty stack and, within a loop, repeatedly execute the following try block: try { i n t s t a c k . pop ( ) ; } catch ( e x c...
What is the java root class for exceptions? java.lang.throw java.lang.exceptions java.lang.errors java.lang.Throwable Which statement about exceptions...
What is the java root class for exceptions? java.lang.throw java.lang.exceptions java.lang.errors java.lang.Throwable Which statement about exceptions is NOT true. Exception handling enables a program to deal with errors during execution. Exceptions are compile time errors. Exceptions are thrown from a method. An exception is an Exceptions can be primitives or objects. True False "try-with-resources" syntax is used to ___________________. automatically close the files used in the program. throw an exception for a memory related error. all of the above validate...
*IN JAVA* EXCEPTION HANDLING Concept Summary: 1. Use of try… catch in a program 2. Define...
*IN JAVA* EXCEPTION HANDLING Concept Summary: 1. Use of try… catch in a program 2. Define an exception class and call it from the driver program. For this lab you will complete two parts. Part (a) of the lab implements try… catch and uses an existing exception in C# or in Java. Write a program that implements an ArrayIndexOutOfBounds error. Part (b) writes a program that converts a time from 24-hour notation to 12-hour notation. Assume the user will enter...
Apply JavaFX and exception handling to design a CircleApp class using proper JavaFX GUI components, such...
Apply JavaFX and exception handling to design a CircleApp class using proper JavaFX GUI components, such as labels, text fields and buttons(Submit, Clear, and Exit) to compute the area of circle and display the radius user entered in the text field and computing result in a proper location in the application windows. It will also verify invalid data entries for radius(No letters and must be a postive real number) using expection handling. Your code will also have a custom-designed exception...
PYTHON 3: must use try/except for exception handling Write a function extractInt() that takes a string...
PYTHON 3: must use try/except for exception handling Write a function extractInt() that takes a string as a parameter and returns an integer constructed out of the digits that appear in the string. The digits in the integer should appear in the same order as the digits in the string. If the string does not contain any digits or an empty string is provided as a parameter, the value 0 should be return.
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt...
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt user for input. When done it should give an option to compute another GPA or exit.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT