Deck 9: Exception Handling

Full screen (f)
exit full mode
Question
The Exception class belongs to the package:
(a)java.io
(b)java.util
(c)java.lang
(d)java.except
Use Space or
up arrow
down arrow
to flip the card.
Question
The basic way of handling exceptions in Java consists of the try-catch-throw trio.
Question
All exceptions are descendants of the class:
(a)Throwable
(b)Catchable
(c)Tryable
(d)Blockable
Question
The catch block has ________ parameters.
(a)zero
(b)one
(c)two
(d)three
Question
The execution of a throw statement is referred to as:
(a)catching a block
(b)trying a block
(c)handling an exception
(d)throwing an exception
Question
When using the Scanner class one should account for a/an:
(a)NumberFormatException
(b)InputMismatchException
(c)ArrayIndexOutOfBoundsException
(d)PowerFailureException
Question
A ___________ block should immediately follow a try block.
(a)try
(b)catch
(c)fail
(d)final
Question
If a method throws an exception,and the exception is not caught inside the method,then the method invocation:
(a)terminates
(b)transfers control to the catch block
(c)transfers control to the exception handler
(d)none of the above
Question
If a method does not catch an exception,then it must at least warn programmers that any invocation of the method might possibly throw an exception.This warning is called a/an:
(a)Exception handler
(b)Throws clause
(c)Try block
(d)Catch block
Question
A _________ block executes regardless of whether an exception occurs.
(a)final
(b)finally
(c)catch
(d)none of the above
Question
ArrayIndexOutOfBoundsException is a descendent of the class RuntimeException.This means:
(a)the exception must be caught
(b)a finally block must be included
(c)the exception does not have to be explicitly caught
(d)none of the above
Question
A runtime exception is a/an:
(a)checked exception
(b)unchecked exception
(c)offending exception
(d)none of the above
Question
The throw operator causes a change in the flow of control.
Question
Which circumstance is an exception to the catch or declare rule?
(a)Exceptions that result from errors of some sort.
(b)Exceptions that are descendents of the class RuntimeException.
(c)Both A and B
(d)None of the above
Question
Exception handling is an example of a programming methodology known as:
(a)structured programming
(b)object oriented programming
(c)goto programming
(d)event-driven programming
Question
Methods that process String arguments as if they were numbers could possibly throw a/an _________ exception.
(a)NumberFormatException
(b)NullPointerException
(c)both a and b
(d)none of the above
Question
Try blocks contain code that could possibly:
(a)handle an exception
(b)throw an exception
(c)catch an exception
(d)display an exception
Question
Exceptions that are subject to the catch or declare rule are called:
(a)Checked exceptions
(b)Unchecked exceptions
(c)Fatal exceptions
(d)All of the above
Question
An exception is caught in a _________ block.
(a)try
(b)catch
(c)finally
(d)all of the above
Question
When defining your own exception class,you extend an existing exception class.This is an example of:
(a)polymorphism
(b)encapsulation
(c)inheritance
(d)all of the above
Question
The finally block contains code to be executed whether or not an exception is thrown in a try block.
Question
You can not place a try block and its following catch blocks inside a larger try block or inside a larger catch block.
Question
Every exception class is an ancestor of the class Exception.
Question
Define an exception class called NegativeNumberException.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "Negative Number Not Allowed!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.
Question
Use a catch block to display the exception thrown in number two above.
Question
What is the catch or declare rule?
Question
Define an exception class called DiskDriveNotReady.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "Disk Drive Not Ready!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.
Question
A program can catch multiple exceptions.
Question
When an exception is thrown,the code in the surrounding try block continues executing and then the catch block begins execution.
Question
Revise the program in number 9 above to throw a NegativeNumberException if the user enters a negative number.
Question
The compiler does not complain when the catch or declare rule is ignored.
Question
Write a complete Java program that prompts the user for two nonnegative integer numbers.Your program should handle bad input data.
Question
Write a Java statement that throws a new exception with the String: Disk drive not ready.
Question
Write a Java statement that throws a new exception with the String: File Not Found.
Question
Use a catch block to display the exception thrown in number one above.
Question
Exceptions that must follow the Catch or Declare Rule are often called unchecked exceptions.
Question
Revise the program in number 8 above to use a try/catch block to handle the IOException.
Question
In event-driven programming,sending an event is called firing the event.
Question
Define an exception class called FileNotFoundException.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "File Not Found!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.
Question
The two most important things about an exception object are its type and the message that it carries in an instance variable of type String.
Question
List five common examples of exceptions that occur.
Question
Should an application catch objects of type Error?
Question
What is the purpose of the method getMessage()when used with exception handling?
Question
If you were going to catch an exception of type Exception,where should this catch block be placed within your code?
Question
What is the purpose of the finally block?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/45
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Exception Handling
1
The Exception class belongs to the package:
(a)java.io
(b)java.util
(c)java.lang
(d)java.except
C
2
The basic way of handling exceptions in Java consists of the try-catch-throw trio.
False
3
All exceptions are descendants of the class:
(a)Throwable
(b)Catchable
(c)Tryable
(d)Blockable
A
4
The catch block has ________ parameters.
(a)zero
(b)one
(c)two
(d)three
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
5
The execution of a throw statement is referred to as:
(a)catching a block
(b)trying a block
(c)handling an exception
(d)throwing an exception
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
6
When using the Scanner class one should account for a/an:
(a)NumberFormatException
(b)InputMismatchException
(c)ArrayIndexOutOfBoundsException
(d)PowerFailureException
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
7
A ___________ block should immediately follow a try block.
(a)try
(b)catch
(c)fail
(d)final
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
8
If a method throws an exception,and the exception is not caught inside the method,then the method invocation:
(a)terminates
(b)transfers control to the catch block
(c)transfers control to the exception handler
(d)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
9
If a method does not catch an exception,then it must at least warn programmers that any invocation of the method might possibly throw an exception.This warning is called a/an:
(a)Exception handler
(b)Throws clause
(c)Try block
(d)Catch block
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
10
A _________ block executes regardless of whether an exception occurs.
(a)final
(b)finally
(c)catch
(d)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
11
ArrayIndexOutOfBoundsException is a descendent of the class RuntimeException.This means:
(a)the exception must be caught
(b)a finally block must be included
(c)the exception does not have to be explicitly caught
(d)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
12
A runtime exception is a/an:
(a)checked exception
(b)unchecked exception
(c)offending exception
(d)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
13
The throw operator causes a change in the flow of control.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
14
Which circumstance is an exception to the catch or declare rule?
(a)Exceptions that result from errors of some sort.
(b)Exceptions that are descendents of the class RuntimeException.
(c)Both A and B
(d)None of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
15
Exception handling is an example of a programming methodology known as:
(a)structured programming
(b)object oriented programming
(c)goto programming
(d)event-driven programming
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
16
Methods that process String arguments as if they were numbers could possibly throw a/an _________ exception.
(a)NumberFormatException
(b)NullPointerException
(c)both a and b
(d)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
17
Try blocks contain code that could possibly:
(a)handle an exception
(b)throw an exception
(c)catch an exception
(d)display an exception
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
18
Exceptions that are subject to the catch or declare rule are called:
(a)Checked exceptions
(b)Unchecked exceptions
(c)Fatal exceptions
(d)All of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
19
An exception is caught in a _________ block.
(a)try
(b)catch
(c)finally
(d)all of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
20
When defining your own exception class,you extend an existing exception class.This is an example of:
(a)polymorphism
(b)encapsulation
(c)inheritance
(d)all of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
21
The finally block contains code to be executed whether or not an exception is thrown in a try block.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
22
You can not place a try block and its following catch blocks inside a larger try block or inside a larger catch block.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
23
Every exception class is an ancestor of the class Exception.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
24
Define an exception class called NegativeNumberException.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "Negative Number Not Allowed!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
25
Use a catch block to display the exception thrown in number two above.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
26
What is the catch or declare rule?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
27
Define an exception class called DiskDriveNotReady.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "Disk Drive Not Ready!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
28
A program can catch multiple exceptions.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
29
When an exception is thrown,the code in the surrounding try block continues executing and then the catch block begins execution.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
30
Revise the program in number 9 above to throw a NegativeNumberException if the user enters a negative number.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
31
The compiler does not complain when the catch or declare rule is ignored.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
32
Write a complete Java program that prompts the user for two nonnegative integer numbers.Your program should handle bad input data.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
33
Write a Java statement that throws a new exception with the String: Disk drive not ready.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
34
Write a Java statement that throws a new exception with the String: File Not Found.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
35
Use a catch block to display the exception thrown in number one above.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
36
Exceptions that must follow the Catch or Declare Rule are often called unchecked exceptions.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
37
Revise the program in number 8 above to use a try/catch block to handle the IOException.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
38
In event-driven programming,sending an event is called firing the event.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
39
Define an exception class called FileNotFoundException.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "File Not Found!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
40
The two most important things about an exception object are its type and the message that it carries in an instance variable of type String.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
41
List five common examples of exceptions that occur.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
42
Should an application catch objects of type Error?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
43
What is the purpose of the method getMessage()when used with exception handling?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
44
If you were going to catch an exception of type Exception,where should this catch block be placed within your code?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
45
What is the purpose of the finally block?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 45 flashcards in this deck.