Deck 11: Exception Handling

Full screen (f)
exit full mode
Question
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
Use Space or
up arrow
down arrow
to flip the card.
Question
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()
Question
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
Question
Errors you discover when compiling a program are considered to be exceptions.
Question
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
Question
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
Question
You can terminate an application with the ____ method.

A) Environment.Exit()
B) Environment.Bye()
C) Environment.Quit()
D) Environment.Terminate()
Question
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
Question
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
Question
____ 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
Question
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
Question
C# has more than 100 defined Exception subclasses.
Question
You can place any number of statements in a try block, including those you know will never throw an exception.
Question
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
Question
You can deliberately generate a SystemException by forcing a program to contain an error.
Question
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
Question
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()
Question
Each ____ block can "catch" one type of Exception .

A) finally
B) catch
C) try
D) Exception
Question
If you are working on a professional project, Microsoft recommends that you use the general Exception class in a catch block.
Question
____ 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
Question
When an Exception object is thrown and multiple catch blocks are present, what happens?
Question
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
Question
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?
Question
____ 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
Question
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?
Question
The StackTrace property of an Exception can be a useful debugging tool. How is this property used when debugging?
Question
The term ____________________ refers to any process that is crucial to an organization.
Question
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
Question
____________________ applications are designed so that they continue to operate, possibly at a reduced level, when some part of the system fails.
Question
A(n) ____________________ is any error condition or unexpected behavior in an executing program.
Question
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
Question
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.
Question
Why might a finally block be necessary?
Question
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?
Question
Most exceptions that are used by programmers derive from three C# classes. What are those classes?
Question
The system of passing an exception through a chain of calling methods is called ____ the exception.

A) propagating
B) tracing
C) stacking
D) inheriting
Question
The object-oriented techniques used to manage errors make up the group of methods known as ____________________.
Question
An exception of class _____________________________________________ is thrown when a method call is invalid for the object's current state.
Question
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
Question
Show the syntax (the general form) of a try … catch pair.
Question
Match between columns
Used to rethrow an Exception
IndexOutOfRangeException
Used to rethrow an Exception
finally block
Used to rethrow an Exception
IOException
Used to rethrow an Exception
unreachable code
Used to rethrow an Exception
catch block
Used to rethrow an Exception
InvalidPrinterException
Used to rethrow an Exception
Environment.Exit()
Used to rethrow an Exception
System.ArgumentException
Used to rethrow an Exception
throw
Performs clean-up tasks at the end of a try … catch sequence
IndexOutOfRangeException
Performs clean-up tasks at the end of a try … catch sequence
finally block
Performs clean-up tasks at the end of a try … catch sequence
IOException
Performs clean-up tasks at the end of a try … catch sequence
unreachable code
Performs clean-up tasks at the end of a try … catch sequence
catch block
Performs clean-up tasks at the end of a try … catch sequence
InvalidPrinterException
Performs clean-up tasks at the end of a try … catch sequence
Environment.Exit()
Performs clean-up tasks at the end of a try … catch sequence
System.ArgumentException
Performs clean-up tasks at the end of a try … catch sequence
throw
Occurs when an array subscript is not within the allowed range
IndexOutOfRangeException
Occurs when an array subscript is not within the allowed range
finally block
Occurs when an array subscript is not within the allowed range
IOException
Occurs when an array subscript is not within the allowed range
unreachable code
Occurs when an array subscript is not within the allowed range
catch block
Occurs when an array subscript is not within the allowed range
InvalidPrinterException
Occurs when an array subscript is not within the allowed range
Environment.Exit()
Occurs when an array subscript is not within the allowed range
System.ArgumentException
Occurs when an array subscript is not within the allowed range
throw
Exception class for when a user requests an invalid printer
IndexOutOfRangeException
Exception class for when a user requests an invalid printer
finally block
Exception class for when a user requests an invalid printer
IOException
Exception class for when a user requests an invalid printer
unreachable code
Exception class for when a user requests an invalid printer
catch block
Exception class for when a user requests an invalid printer
InvalidPrinterException
Exception class for when a user requests an invalid printer
Environment.Exit()
Exception class for when a user requests an invalid printer
System.ArgumentException
Exception class for when a user requests an invalid printer
throw
Sometimes referred to as a catch clause
IndexOutOfRangeException
Sometimes referred to as a catch clause
finally block
Sometimes referred to as a catch clause
IOException
Sometimes referred to as a catch clause
unreachable code
Sometimes referred to as a catch clause
catch block
Sometimes referred to as a catch clause
InvalidPrinterException
Sometimes referred to as a catch clause
Environment.Exit()
Sometimes referred to as a catch clause
System.ArgumentException
Sometimes referred to as a catch clause
throw
Thrown when one of the arguments provided to a method is not valid
IndexOutOfRangeException
Thrown when one of the arguments provided to a method is not valid
finally block
Thrown when one of the arguments provided to a method is not valid
IOException
Thrown when one of the arguments provided to a method is not valid
unreachable code
Thrown when one of the arguments provided to a method is not valid
catch block
Thrown when one of the arguments provided to a method is not valid
InvalidPrinterException
Thrown when one of the arguments provided to a method is not valid
Environment.Exit()
Thrown when one of the arguments provided to a method is not valid
System.ArgumentException
Thrown when one of the arguments provided to a method is not valid
throw
Terminates a program and passes the argument (which can be any integer) to the operating system
IndexOutOfRangeException
Terminates a program and passes the argument (which can be any integer) to the operating system
finally block
Terminates a program and passes the argument (which can be any integer) to the operating system
IOException
Terminates a program and passes the argument (which can be any integer) to the operating system
unreachable code
Terminates a program and passes the argument (which can be any integer) to the operating system
catch block
Terminates a program and passes the argument (which can be any integer) to the operating system
InvalidPrinterException
Terminates a program and passes the argument (which can be any integer) to the operating system
Environment.Exit()
Terminates a program and passes the argument (which can be any integer) to the operating system
System.ArgumentException
Terminates a program and passes the argument (which can be any integer) to the operating system
throw
Exception class for input and output errors
IndexOutOfRangeException
Exception class for input and output errors
finally block
Exception class for input and output errors
IOException
Exception class for input and output errors
unreachable code
Exception class for input and output errors
catch block
Exception class for input and output errors
InvalidPrinterException
Exception class for input and output errors
Environment.Exit()
Exception class for input and output errors
System.ArgumentException
Exception class for input and output errors
throw
Also called dead code
IndexOutOfRangeException
Also called dead code
finally block
Also called dead code
IOException
Also called dead code
unreachable code
Also called dead code
catch block
Also called dead code
InvalidPrinterException
Also called dead code
Environment.Exit()
Also called dead code
System.ArgumentException
Also called dead code
throw
Question
What types of objects can be explicitly thrown?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
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
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()
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
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
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
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()
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
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
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
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
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
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
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()
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
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
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
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
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?
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
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
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
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
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
Used to rethrow an Exception
IndexOutOfRangeException
Used to rethrow an Exception
finally block
Used to rethrow an Exception
IOException
Used to rethrow an Exception
unreachable code
Used to rethrow an Exception
catch block
Used to rethrow an Exception
InvalidPrinterException
Used to rethrow an Exception
Environment.Exit()
Used to rethrow an Exception
System.ArgumentException
Used to rethrow an Exception
throw
Performs clean-up tasks at the end of a try … catch sequence
IndexOutOfRangeException
Performs clean-up tasks at the end of a try … catch sequence
finally block
Performs clean-up tasks at the end of a try … catch sequence
IOException
Performs clean-up tasks at the end of a try … catch sequence
unreachable code
Performs clean-up tasks at the end of a try … catch sequence
catch block
Performs clean-up tasks at the end of a try … catch sequence
InvalidPrinterException
Performs clean-up tasks at the end of a try … catch sequence
Environment.Exit()
Performs clean-up tasks at the end of a try … catch sequence
System.ArgumentException
Performs clean-up tasks at the end of a try … catch sequence
throw
Occurs when an array subscript is not within the allowed range
IndexOutOfRangeException
Occurs when an array subscript is not within the allowed range
finally block
Occurs when an array subscript is not within the allowed range
IOException
Occurs when an array subscript is not within the allowed range
unreachable code
Occurs when an array subscript is not within the allowed range
catch block
Occurs when an array subscript is not within the allowed range
InvalidPrinterException
Occurs when an array subscript is not within the allowed range
Environment.Exit()
Occurs when an array subscript is not within the allowed range
System.ArgumentException
Occurs when an array subscript is not within the allowed range
throw
Exception class for when a user requests an invalid printer
IndexOutOfRangeException
Exception class for when a user requests an invalid printer
finally block
Exception class for when a user requests an invalid printer
IOException
Exception class for when a user requests an invalid printer
unreachable code
Exception class for when a user requests an invalid printer
catch block
Exception class for when a user requests an invalid printer
InvalidPrinterException
Exception class for when a user requests an invalid printer
Environment.Exit()
Exception class for when a user requests an invalid printer
System.ArgumentException
Exception class for when a user requests an invalid printer
throw
Sometimes referred to as a catch clause
IndexOutOfRangeException
Sometimes referred to as a catch clause
finally block
Sometimes referred to as a catch clause
IOException
Sometimes referred to as a catch clause
unreachable code
Sometimes referred to as a catch clause
catch block
Sometimes referred to as a catch clause
InvalidPrinterException
Sometimes referred to as a catch clause
Environment.Exit()
Sometimes referred to as a catch clause
System.ArgumentException
Sometimes referred to as a catch clause
throw
Thrown when one of the arguments provided to a method is not valid
IndexOutOfRangeException
Thrown when one of the arguments provided to a method is not valid
finally block
Thrown when one of the arguments provided to a method is not valid
IOException
Thrown when one of the arguments provided to a method is not valid
unreachable code
Thrown when one of the arguments provided to a method is not valid
catch block
Thrown when one of the arguments provided to a method is not valid
InvalidPrinterException
Thrown when one of the arguments provided to a method is not valid
Environment.Exit()
Thrown when one of the arguments provided to a method is not valid
System.ArgumentException
Thrown when one of the arguments provided to a method is not valid
throw
Terminates a program and passes the argument (which can be any integer) to the operating system
IndexOutOfRangeException
Terminates a program and passes the argument (which can be any integer) to the operating system
finally block
Terminates a program and passes the argument (which can be any integer) to the operating system
IOException
Terminates a program and passes the argument (which can be any integer) to the operating system
unreachable code
Terminates a program and passes the argument (which can be any integer) to the operating system
catch block
Terminates a program and passes the argument (which can be any integer) to the operating system
InvalidPrinterException
Terminates a program and passes the argument (which can be any integer) to the operating system
Environment.Exit()
Terminates a program and passes the argument (which can be any integer) to the operating system
System.ArgumentException
Terminates a program and passes the argument (which can be any integer) to the operating system
throw
Exception class for input and output errors
IndexOutOfRangeException
Exception class for input and output errors
finally block
Exception class for input and output errors
IOException
Exception class for input and output errors
unreachable code
Exception class for input and output errors
catch block
Exception class for input and output errors
InvalidPrinterException
Exception class for input and output errors
Environment.Exit()
Exception class for input and output errors
System.ArgumentException
Exception class for input and output errors
throw
Also called dead code
IndexOutOfRangeException
Also called dead code
finally block
Also called dead code
IOException
Also called dead code
unreachable code
Also called dead code
catch block
Also called dead code
InvalidPrinterException
Also called dead code
Environment.Exit()
Also called dead code
System.ArgumentException
Also called dead code
throw
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
locked card icon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.