Deck 11: Exception Handling
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
Play
Full screen (f)
Deck 11: Exception Handling
1
In C#, all exceptions are objects that are members of the ____ class or one of its derived classes.
A) ApplicationException
B) Exception
C) SystemException
D) RuntimeException
A) ApplicationException
B) Exception
C) SystemException
D) RuntimeException
B
2
The ____ methods are used to convert string data to another data type, such as int , double , or bool , without fear of generating an exception.
A) TryData()
B) TryFromString()
C) TryParse()
D) TryConvert()
A) TryData()
B) TryFromString()
C) TryParse()
D) TryConvert()
C
3
Typically, you use the ____ block to perform clean-up tasks that must occur, regardless of whether any errors occurred or were caught.
A) default
B) always
C) execute
D) finally
A) default
B) always
C) execute
D) finally
D
4
Errors you discover when compiling a program are considered to be exceptions.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
When you write a block of code in which something can go wrong, you can place the code in a(n) ____ block.
A) try
B) catch
C) finally
D) exception
A) try
B) catch
C) finally
D) exception
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
The creators of C# define an infrequent event in code as one that happens in less than ____ percent of all program executions.
A) 10
B) 25
C) 30
D) 35
A) 10
B) 25
C) 30
D) 35
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
You can terminate an application with the ____ method.
A) Environment.Exit()
B) Environment.Bye()
C) Environment.Quit()
D) Environment.Terminate()
A) Environment.Exit()
B) Environment.Bye()
C) Environment.Quit()
D) Environment.Terminate()
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
An exception of the ____ class is thrown when an ongoing operation is aborted by the user.
A) System.InvalidOperationException
B) System.ArithmeticException
C) System.Data.OperationAbortedException
D) System.InvalidCastException
A) System.InvalidOperationException
B) System.ArithmeticException
C) System.Data.OperationAbortedException
D) System.InvalidCastException
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
An exception of the ____ class is thrown when an attempt is made to store an element of the wrong type within an array.
A) System.ArrayTypeMismatchException
B) System.ArithmeticException
C) System.FormatException
D) System.InvalidCastException
A) System.ArrayTypeMismatchException
B) System.ArithmeticException
C) System.FormatException
D) System.InvalidCastException
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
____ blocks contain statements that can never execute under any circumstances because the program logic "can't get there."
A) Default
B) catch
C) finally
D) Unreachable
A) Default
B) catch
C) finally
D) Unreachable
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
The Exception class contains a read-only property named ____ that contains useful information about an Exception object.
A) StackTrace
B) Message
C) toString
D) ThrownText
A) StackTrace
B) Message
C) toString
D) ThrownText
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
C# has more than 100 defined Exception subclasses.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
You can place any number of statements in a try block, including those you know will never throw an exception.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
Like all other classes in the C# programming language, the Exception class is a descendant of the ____ class.
A) System
B) Application
C) CLR
D) Object
A) System
B) Application
C) CLR
D) Object
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
You can deliberately generate a SystemException by forcing a program to contain an error.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
The ____ block is used frequently with file input and output to ensure that open files are closed.
A) execute
B) always
C) finally
D) default
A) execute
B) always
C) finally
D) default
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
The Exception class overrides ____ to provide a descriptive error message so a user can receive precise information about the nature of any Exception that is thrown.
A) Message()
B) StackTrace()
C) ToString()
D) ThrownMessage()
A) Message()
B) StackTrace()
C) ToString()
D) ThrownMessage()
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
Each ____ block can "catch" one type of Exception .
A) finally
B) catch
C) try
D) Exception
A) finally
B) catch
C) try
D) Exception
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
If you are working on a professional project, Microsoft recommends that you use the general Exception class in a catch block.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
____ represents the degree to which a system is resilient to stress and able to maintain correct functioning.
A) Fault tolerance
B) Mission critical
C) Forgiveness
D) Robustness
A) Fault tolerance
B) Mission critical
C) Forgiveness
D) Robustness
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
When an Exception object is thrown and multiple catch blocks are present, what happens?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
The memory location where the computer stores the list of locations to which the system must return is known as the ____.
A) method call
B) memory call
C) call stack
D) function call
A) method call
B) memory call
C) call stack
D) function call
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
When you design classes containing methods that have statements that might throw exceptions, you can create the methods so they throw the Exception object but do not handle it. Why might you want to do this?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
____ is the type of exception automatically generated if there is a problem opening a file, reading data from a file, or writing to a file.
A) FileException
B) StorageException
C) FException
D) IOException
A) FileException
B) StorageException
C) FException
D) IOException
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
The following example shows how a programmer might avoid a division by zero error by explicitly checking for the error condition:
if (gallonsOfGas != 0)
mpg = milesDriven /gallonsOfGas;
else mpg = 0;
Another possible way to deal with this is to use exception handling mechanisms. What factors help the programmer decide which of these methods to use?
if (gallonsOfGas != 0)
mpg = milesDriven /gallonsOfGas;
else mpg = 0;
Another possible way to deal with this is to use exception handling mechanisms. What factors help the programmer decide which of these methods to use?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
The StackTrace property of an Exception can be a useful debugging tool. How is this property used when debugging?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
The term ____________________ refers to any process that is crucial to an organization.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
To create your own Exception that you can throw, you can extend the ApplicationException class, which is a subclass of ____.
A) SystemException
B) Exception
C) ObjectException
D) MainException
A) SystemException
B) Exception
C) ObjectException
D) MainException
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
____________________ applications are designed so that they continue to operate, possibly at a reduced level, when some part of the system fails.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
A(n) ____________________ is any error condition or unexpected behavior in an executing program.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
When you catch an Exception , you can print the value of the ____ property to display a list of methods in the call stack so you can determine the location of the Exception .
A) StackTrace
B) CallTrace
C) MethodTrace
D) ClassTrace
A) StackTrace
B) CallTrace
C) MethodTrace
D) ClassTrace
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
The int version of the TryParse() methods converts string data to an int . The first argument is the string that you want to convert, and the second argument is an out parameter that receives the result if the conversion is successful, or 0 if it is not. The method returns a Boolean value that indicates whether the conversion was successful. Write this method using exception handling techniques to ensure that the method returns correctly whether or not the conversion is successful. Use the method Convert.ToInt32(inputString) to do the conversion.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
Why might a finally block be necessary?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
If a finally block is associated with a try … catch pair, what are the three possible outcomes of the try that result in execution of the finally block?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
Most exceptions that are used by programmers derive from three C# classes. What are those classes?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
The system of passing an exception through a chain of calling methods is called ____ the exception.
A) propagating
B) tracing
C) stacking
D) inheriting
A) propagating
B) tracing
C) stacking
D) inheriting
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
The object-oriented techniques used to manage errors make up the group of methods known as ____________________.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
An exception of class _____________________________________________ is thrown when a method call is invalid for the object's current state.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
When you write a method that catches an Exception , your method does not have to handle it. Instead, you might choose to ____ the exception to the method that called your method.
A) rethrow
B) save
C) open
D) delete
A) rethrow
B) save
C) open
D) delete
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
Show the syntax (the general form) of a try … catch pair.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
What types of objects can be explicitly thrown?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck