Deck 11: Exceptions

ملء الشاشة (f)
exit full mode
سؤال
An unchecked exception is an exception that must either be caught and handled or listed in the throws clause of any method that might throw or propagate it.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
In order to have some code throw an exception, which of the following reserved words should you use?

A) throw
B) throws
C) try
D) Throwable
E) goto
سؤال
Which of the following messages passed to the String str could throw a StringIndexOutOfBoundsException?

A) str length();
B) str charAt(2);
C) str replace('a', 'A');
D) str equals(str);
E) Any of these could throw a StringIndexOutOfBoundsException
سؤال
The difference between the throw reserved word and the throws reserved word is that throw is used within a method body, while throws is used within a method header.
سؤال
Programmers can define their own exceptions by extending the Exception class or one of the descendants of this class.
سؤال
If an exception is thrown and not caught anywhere in the program, then the program terminates.
سؤال
NullPointerExceptions and ArithmeticExceptions are both derived from which class?

A) Error
B) Exception
C) RuntimeException
D) IllegalAccessException
E) CheckedException
سؤال
Example Code Ch 11-1
public static void main(String[] args)
{
try
{
ExceptionThrowerCode etc = new ExceptionThrowerCode();
etc.m1();
etc.m2();
}
catch (ArithmeticException ae) { ... }
}
public class ExceptionThrowerCode
{
...
public void m1()
{
...
}
public void m2()
{
try
{
m3();
}
catch(ArithmeticException ae) {...}
catch(NullPointerException npe) {...}
}
public void m3()
{
try
{
...
}
catch(ArithmeticException ae) {...}
}
}
Refer to Example Code Ch 11-1: If a NullPointerException arises in the try statement in m1

A) it is caught in main
B) it is caught in m1
C) it is caught in m2
D) it is caught in m3
E) it is not caught and the program terminates
سؤال
A try statement must have at least one catch statements but could have many catch statements and may or may not have a finally clause.
سؤال
While the Exception class is part of java.lang, IOException is part of java.io.
سؤال
A Java program can handle an exception in several different ways. Which of the following is not a way a Java program might handle an exception?

A) ignore the exception
B) handle the exception where it arises using try and catch statements
C) propagate the exception to another method where it can be handled
D) throw the exception to a predefined Exception class to be handled
E) All of these are valid ways to handle an exception
سؤال
All run-time errors throw exceptions.
سؤال
If an exception arises in a catch statement, and the exception is of the type caught by the catch statement, then the catch statement catches the same exception. For instance, if the following catch statement first catches an ArithmeticException and, while executing, throws another ArithmeticException, it is able to catch the second ArithmeticException as well the first.
catch (ArithmeticException ex) {...}
سؤال
An exception that could also arise in the try statement that does not have an associated catch statement is

A) ClassNotFoundException
B) IllegalArgumentException
C) NegativeArraySizeException
D) NullPointerException
E) OutOfMemoryException
سؤال
Example Code Ch 11-1
public static void main(String[] args)
{
try
{
ExceptionThrowerCode etc = new ExceptionThrowerCode();
etc.m1();
etc.m2();
}
catch (ArithmeticException ae) { ... }
}
public class ExceptionThrowerCode
{
...
public void m1()
{
...
}
public void m2()
{
try
{
m3();
}
catch(ArithmeticException ae) {...}
catch(NullPointerException npe) {...}
}
public void m3()
{
try
{
...
}
catch(ArithmeticException ae) {...}
}
}
Refer to Example Code Ch 11-1: If an ArithmeticException arises in the try statement in m3

A) it is caught in main
B) it is caught in m1
C) it is caught in m2
D) it is caught in m3
E) it is not caught and the program terminates
سؤال
An exception can produce a "call stack trace" which lists

A) the active methods in the order that they were invoked
B) the active methods in the opposite order that they were invoked
C) the values of all instance data of the object where the exception was raised
D) the values of all instance data of the object where the exception was raised and all local variables and parameters of the method where the exception was raised
E) the name of the exception thrown
سؤال
An ArithmeticException is a checked exception.
سؤال
A finally clause will execute

A) only if the try statement that precedes it does not throw an exception
B) only if the try statement that precedes it throws an exception that is caught
C) only if the try statement that precedes it throws an exception that is not caught
D) only if the try statement that precedes it throws an exception, regardless of whether or not it is caught
E) in any circumstance
سؤال
Example Code Ch 11-1
public static void main(String[] args)
{
try
{
ExceptionThrowerCode etc = new ExceptionThrowerCode();
etc.m1();
etc.m2();
}
catch (ArithmeticException ae) { ... }
}
public class ExceptionThrowerCode
{
...
public void m1()
{
...
}
public void m2()
{
try
{
m3();
}
catch(ArithmeticException ae) {...}
catch(NullPointerException npe) {...}
}
public void m3()
{
try
{
...
}
catch(ArithmeticException ae) {...}
}
}
Refer to Example Code Ch 11-1: If a NullPointerException arises in the try statement in m3

A) it is caught in main
B) it is caught in m1
C) it is caught in m2
D) it is caught in m3
E) it is not caught and the program terminates
سؤال
An ArithmeticException is Throwable.
سؤال
Which of the following is not true of the RuntimeException class?

A) All RuntimeException throw checked exceptions.
B) All RuntimeException are Throwable objects.
C) RuntimeException has child classes ArithmeticException and NullPointerException.
D) RuntimeException objects are not Error objects.
E) All of these are true
سؤال
Character streams manage

A) byte-sized data
B) binary data
C) Unicode characters
D) ASCII characters
E) compressed data
سؤال
The difference between a checked and an unchecked exception is

A) checked exceptions need not be listed in a throws clause
B) unchecked exceptions must be listed in a throws clause
C) neither kind of exception follows the rules of exception propagation
D) an unchecked exception requires no throws clause
E) a checked exception always must be caught by a try block while this is not true for an unchecked exception
سؤال
Explain or provide an example showing how an ArithmeticException could arise.
سؤال
A disabled component is

A) one that is grayed out
B) one that is no longer active
C) one that is still visually apparent but no longer functions if clicked
D) provides an indication of functionality that is not currently available
E) All of these are true
سؤال
Why might you want to create your own exception class? What purpose would it serve?
سؤال
The Scanner class provides an abstraction for input operations by

A) using try and catch statements to catch any IOException instead of throwing the Exception elsewhere
B) parsing input lines into individual tokens
C) performing conversion operations from String to the appropriate type as specified in the Scanner message
D) inputting from the standard input stream if create is called using System.in
E) All of these
سؤال
System.err is a(n)

A) input stream
B) GUI dialog box that indicates when an error has arisen
C) object
D) Error subclass
E) RuntimException subclass
سؤال
Explain or provide an example showing how an IOException could arise.
سؤال
When a program terminates because a thrown exception is not handled, the program

A) starts up again automatically
B) opens a dialog box which asks the user whether the program should start again, end, or enter a debugging mode
C) saves all output to a disk file named runStackTrace.txt
D) opens a dialog box for the user to specify a disk filename and all output is stored to that file
E) outputs a message indicating what the exception was and where it was thrown
سؤال
What are the three standard I/O streams and what purposes do they fulfill?
سؤال
Explain or provide an example showing how a NullPointerException could arise.
سؤال
Assume Exceptionname is a checked exception. If a method uses a class that can generate Exceptionname, then either the method must include try and catch statements where a catch statement catches Exceptionname, or the method header must include the statement

A) throw Exceptionname
B) throws Exceptionname
C) catch Exceptionname
D) catches Exceptionname
E) implements Exceptionname
سؤال
A method that uses the Scanner class to obtain input does not require either catching or throwing an IOException. This is because

A) the Scanner class does not call upon any classes that throw checked exceptions
B) the Scanner class's methods call input methods in try statements and catch IOExceptions so that they are handled directly in the Scanner class
C) the Scanner class uses dialog boxes instead of java.io classes so that it does not have to deal with IOExceptions
D) the Scanner class overrides the class IOException making it an unchecked exception
E) None of the above; methods do require handling IOExceptions even if thrown by a method in a Scanner class
سؤال
The term "exception propagation" means

A) an exception is caught by the first catch clause
B) an exception not caught by the first catch clause is caught by an outer (enclosing) catch clause
C) exceptions are caught, sequentially, by catch clauses in the current try block
D) exceptions are always caught by the outermost try block
E) None of these explain what exception propagation is
سؤال
Explain or provide an example showing how an IndexOutOfBoundsException could arise.
سؤال
A processing stream is a data stream that

A) can manage both input streams and output streams at the same time
B) performs some manipulation or process on the data
C) can only manage input streams
D) operates on input and output devices but not files
E) can manage byte streams and character streams at the same time
سؤال
Explain or provide an example showing how a NumberFormatException could arise.
سؤال
Explain what happens if an exception is not caught.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/39
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 11: Exceptions
1
An unchecked exception is an exception that must either be caught and handled or listed in the throws clause of any method that might throw or propagate it.
False
2
In order to have some code throw an exception, which of the following reserved words should you use?

A) throw
B) throws
C) try
D) Throwable
E) goto
A
3
Which of the following messages passed to the String str could throw a StringIndexOutOfBoundsException?

A) str length();
B) str charAt(2);
C) str replace('a', 'A');
D) str equals(str);
E) Any of these could throw a StringIndexOutOfBoundsException
B
4
The difference between the throw reserved word and the throws reserved word is that throw is used within a method body, while throws is used within a method header.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
5
Programmers can define their own exceptions by extending the Exception class or one of the descendants of this class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
6
If an exception is thrown and not caught anywhere in the program, then the program terminates.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
7
NullPointerExceptions and ArithmeticExceptions are both derived from which class?

A) Error
B) Exception
C) RuntimeException
D) IllegalAccessException
E) CheckedException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
8
Example Code Ch 11-1
public static void main(String[] args)
{
try
{
ExceptionThrowerCode etc = new ExceptionThrowerCode();
etc.m1();
etc.m2();
}
catch (ArithmeticException ae) { ... }
}
public class ExceptionThrowerCode
{
...
public void m1()
{
...
}
public void m2()
{
try
{
m3();
}
catch(ArithmeticException ae) {...}
catch(NullPointerException npe) {...}
}
public void m3()
{
try
{
...
}
catch(ArithmeticException ae) {...}
}
}
Refer to Example Code Ch 11-1: If a NullPointerException arises in the try statement in m1

A) it is caught in main
B) it is caught in m1
C) it is caught in m2
D) it is caught in m3
E) it is not caught and the program terminates
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
9
A try statement must have at least one catch statements but could have many catch statements and may or may not have a finally clause.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
10
While the Exception class is part of java.lang, IOException is part of java.io.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
11
A Java program can handle an exception in several different ways. Which of the following is not a way a Java program might handle an exception?

A) ignore the exception
B) handle the exception where it arises using try and catch statements
C) propagate the exception to another method where it can be handled
D) throw the exception to a predefined Exception class to be handled
E) All of these are valid ways to handle an exception
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
12
All run-time errors throw exceptions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
13
If an exception arises in a catch statement, and the exception is of the type caught by the catch statement, then the catch statement catches the same exception. For instance, if the following catch statement first catches an ArithmeticException and, while executing, throws another ArithmeticException, it is able to catch the second ArithmeticException as well the first.
catch (ArithmeticException ex) {...}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
14
An exception that could also arise in the try statement that does not have an associated catch statement is

A) ClassNotFoundException
B) IllegalArgumentException
C) NegativeArraySizeException
D) NullPointerException
E) OutOfMemoryException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
15
Example Code Ch 11-1
public static void main(String[] args)
{
try
{
ExceptionThrowerCode etc = new ExceptionThrowerCode();
etc.m1();
etc.m2();
}
catch (ArithmeticException ae) { ... }
}
public class ExceptionThrowerCode
{
...
public void m1()
{
...
}
public void m2()
{
try
{
m3();
}
catch(ArithmeticException ae) {...}
catch(NullPointerException npe) {...}
}
public void m3()
{
try
{
...
}
catch(ArithmeticException ae) {...}
}
}
Refer to Example Code Ch 11-1: If an ArithmeticException arises in the try statement in m3

A) it is caught in main
B) it is caught in m1
C) it is caught in m2
D) it is caught in m3
E) it is not caught and the program terminates
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
16
An exception can produce a "call stack trace" which lists

A) the active methods in the order that they were invoked
B) the active methods in the opposite order that they were invoked
C) the values of all instance data of the object where the exception was raised
D) the values of all instance data of the object where the exception was raised and all local variables and parameters of the method where the exception was raised
E) the name of the exception thrown
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
17
An ArithmeticException is a checked exception.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
18
A finally clause will execute

A) only if the try statement that precedes it does not throw an exception
B) only if the try statement that precedes it throws an exception that is caught
C) only if the try statement that precedes it throws an exception that is not caught
D) only if the try statement that precedes it throws an exception, regardless of whether or not it is caught
E) in any circumstance
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
19
Example Code Ch 11-1
public static void main(String[] args)
{
try
{
ExceptionThrowerCode etc = new ExceptionThrowerCode();
etc.m1();
etc.m2();
}
catch (ArithmeticException ae) { ... }
}
public class ExceptionThrowerCode
{
...
public void m1()
{
...
}
public void m2()
{
try
{
m3();
}
catch(ArithmeticException ae) {...}
catch(NullPointerException npe) {...}
}
public void m3()
{
try
{
...
}
catch(ArithmeticException ae) {...}
}
}
Refer to Example Code Ch 11-1: If a NullPointerException arises in the try statement in m3

A) it is caught in main
B) it is caught in m1
C) it is caught in m2
D) it is caught in m3
E) it is not caught and the program terminates
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
20
An ArithmeticException is Throwable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which of the following is not true of the RuntimeException class?

A) All RuntimeException throw checked exceptions.
B) All RuntimeException are Throwable objects.
C) RuntimeException has child classes ArithmeticException and NullPointerException.
D) RuntimeException objects are not Error objects.
E) All of these are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
22
Character streams manage

A) byte-sized data
B) binary data
C) Unicode characters
D) ASCII characters
E) compressed data
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
23
The difference between a checked and an unchecked exception is

A) checked exceptions need not be listed in a throws clause
B) unchecked exceptions must be listed in a throws clause
C) neither kind of exception follows the rules of exception propagation
D) an unchecked exception requires no throws clause
E) a checked exception always must be caught by a try block while this is not true for an unchecked exception
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
24
Explain or provide an example showing how an ArithmeticException could arise.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
25
A disabled component is

A) one that is grayed out
B) one that is no longer active
C) one that is still visually apparent but no longer functions if clicked
D) provides an indication of functionality that is not currently available
E) All of these are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
26
Why might you want to create your own exception class? What purpose would it serve?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
27
The Scanner class provides an abstraction for input operations by

A) using try and catch statements to catch any IOException instead of throwing the Exception elsewhere
B) parsing input lines into individual tokens
C) performing conversion operations from String to the appropriate type as specified in the Scanner message
D) inputting from the standard input stream if create is called using System.in
E) All of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
28
System.err is a(n)

A) input stream
B) GUI dialog box that indicates when an error has arisen
C) object
D) Error subclass
E) RuntimException subclass
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
29
Explain or provide an example showing how an IOException could arise.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
30
When a program terminates because a thrown exception is not handled, the program

A) starts up again automatically
B) opens a dialog box which asks the user whether the program should start again, end, or enter a debugging mode
C) saves all output to a disk file named runStackTrace.txt
D) opens a dialog box for the user to specify a disk filename and all output is stored to that file
E) outputs a message indicating what the exception was and where it was thrown
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
31
What are the three standard I/O streams and what purposes do they fulfill?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
32
Explain or provide an example showing how a NullPointerException could arise.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
33
Assume Exceptionname is a checked exception. If a method uses a class that can generate Exceptionname, then either the method must include try and catch statements where a catch statement catches Exceptionname, or the method header must include the statement

A) throw Exceptionname
B) throws Exceptionname
C) catch Exceptionname
D) catches Exceptionname
E) implements Exceptionname
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
34
A method that uses the Scanner class to obtain input does not require either catching or throwing an IOException. This is because

A) the Scanner class does not call upon any classes that throw checked exceptions
B) the Scanner class's methods call input methods in try statements and catch IOExceptions so that they are handled directly in the Scanner class
C) the Scanner class uses dialog boxes instead of java.io classes so that it does not have to deal with IOExceptions
D) the Scanner class overrides the class IOException making it an unchecked exception
E) None of the above; methods do require handling IOExceptions even if thrown by a method in a Scanner class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
35
The term "exception propagation" means

A) an exception is caught by the first catch clause
B) an exception not caught by the first catch clause is caught by an outer (enclosing) catch clause
C) exceptions are caught, sequentially, by catch clauses in the current try block
D) exceptions are always caught by the outermost try block
E) None of these explain what exception propagation is
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
36
Explain or provide an example showing how an IndexOutOfBoundsException could arise.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
37
A processing stream is a data stream that

A) can manage both input streams and output streams at the same time
B) performs some manipulation or process on the data
C) can only manage input streams
D) operates on input and output devices but not files
E) can manage byte streams and character streams at the same time
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
38
Explain or provide an example showing how a NumberFormatException could arise.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
39
Explain what happens if an exception is not caught.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.