Deck 11: Exception Handling

Full screen (f)
exit full mode
Question
Errors you discover when compiling a program are considered to be exceptions.
Use Space or
up arrow
down arrow
to flip the card.
Question
All classes in the C# programming language, including the Exception class, are descendants of what built in class?

A) System
B) Application
C) CLR
D) Object
Question
In general, what block do you use to perform clean-up tasks that must occur, regardless of whether any errors occurred or were caught?

A) default block
B) always block
C) execute block
D) finally block
Question
You can deliberately generate a SystemException by forcing a program to contain an error.
Question
A block that contains statements that can never execute under any circumstances due to a program's logic is known as what kind of block?

A) default block
B) comment block
C) finally block
D) unreachable block
Question
What represents the degree to which a system is resilient to stress and able to maintain correct functioning?

A) fault tolerance
B) critical functionality
C) load forgiveness
D) system robustness
Question
What method can be used to terminate an application?

A) Environment.Exit()
B) Environment.Bye()
C) Environment.Quit()
D) Environment.Terminate()
Question
What read-only property in the Exception class contains useful information about an Exception object?

A) StackTrace
B) Message
C) toString
D) ThrownText
Question
When writing a block of code in which something can go wrong, where should you place the block?

A) It should be placed in a try block.
B) It should be placed after a catch statement.
C) It should be prefaced with a finally statement.
D) It should be defined as an exception block.
Question
According to the creators of C#, an infrequent event in code is one that happens in less than what percent of all program executions?

A) 10%
B) 25%
C) 30%
D) 35%
Question
A catch block can catch how many types of Exceptions?

A) An unlimited number of Exception types.
B) Only one can be caught.
C) As many as can be matched.
D) Two, after which the program ends.
Question
In C#, all exceptions are objects that are members or derived members of what specific class?

A) ApplicationException
B) Exception
C) SystemException
D) RuntimeException
Question
What method is overridden by the Exception class in order to provide a descriptive error message and provide a user with precise information about the nature of any Exception that is thrown?

A) Message()
B) StackTrace()
C) ToString()
D) ThrownMessage()
Question
An exception belonging to what specific class is thrown when an attempt is made to store an element of the wrong type within an array?

A) System.ArrayTypeMismatchException
B) System.TypeMismatch
C) System.FormatException
D) System.InvalidCastException
Question
You can place any number of statements in a try block, including those you know will never throw an exception.
Question
What 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
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
What block can you use to ensure that input and output related files are properly closed?

A) execute
B) always
C) finally
D) default
Question
C# has more than 100 defined Exception subclasses.
Question
If you are working on a professional project, Microsoft recommends that you use the general Exception class in a catch block.
Question
The StackTrace property of an Exception can be a useful debugging tool.How is this property used when debugging?
Question
The ApplicationException class is a sublcass of what other class?

A) SystemException
B) Exception
C) ObjectException
D) MainException
Question
What class should you extend in order to create your own Exception that you can throw?

A) ApplicationException
B) ExceptionObject
C) SystemException
D) Object
Question
When creating an Exception class, what is not one of the three recommended constructors needed?

A) A default constructor.
B) A constructor that takes a string message.
C) A constructor that takes a string message and an inner exception.
D) A constructor that takes a byte variable containing memory dumps.
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 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
When you catch an Exception, what property holds a list of methods in the call stack as its value, allowing you to determine the location of the Exception?

A) StackTrace
B) CallTrace
C) MethodTrace
D) ClassTrace
Question
The Environment.Exit() method is part of what namespace?

A) Exception
B) System
C) Quit
D) Language
Question
Most exceptions that are used by programmers derive from three C# classes.What are those classes?
Question
What type of exception is thrown if there is an issue with file operations, such as opening, reading from, or writing to a file?

A) FileException
B) StorageException
C) FException
D) IOException
Question
When an Exception object is thrown and multiple catch blocks are present, what happens?
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
When you write a method that catches an Exception, rather than handling the Exception itself, it can pass the exception to the method that called your method.What is this known as?

A) rethrowing the Exception
B) saving the Exception
C) opening the Exception
D) sideloading the Exception
Question
Show the syntax (the general form) of a try…catch pair.
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
What happens when you divide a floating-point value by 0 in C#?

A) No exception occurs, and the special value Infinity is returned as the result.
B) The program will throw an exception of type System.DivideByZeroException.
C) The program will catch the exception, and return Undefined as the result.
D) The program will crash.
Question
What is the system of passing an exception through a chain of calling methods called?

A) propagating the exception
B) tracing the exception
C) stacking the exception
D) inheriting the exception
Question
The memory location where the computer stores the list of locations to which the system must return is known by what term?

A) The method call trace.
B) The memory call pool.
C) The call stack.
D) The function call.
Question
Why might a finally block be necessary?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/39
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Exception Handling
1
Errors you discover when compiling a program are considered to be exceptions.
False
2
All classes in the C# programming language, including the Exception class, are descendants of what built in class?

A) System
B) Application
C) CLR
D) Object
D
3
In general, what block do you use to perform clean-up tasks that must occur, regardless of whether any errors occurred or were caught?

A) default block
B) always block
C) execute block
D) finally block
D
4
You can deliberately generate a SystemException by forcing a program to contain an error.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
5
A block that contains statements that can never execute under any circumstances due to a program's logic is known as what kind of block?

A) default block
B) comment block
C) finally block
D) unreachable block
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
6
What represents the degree to which a system is resilient to stress and able to maintain correct functioning?

A) fault tolerance
B) critical functionality
C) load forgiveness
D) system robustness
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
7
What method can be used to terminate an application?

A) Environment.Exit()
B) Environment.Bye()
C) Environment.Quit()
D) Environment.Terminate()
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
8
What read-only property in the Exception class contains useful information about an Exception object?

A) StackTrace
B) Message
C) toString
D) ThrownText
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
9
When writing a block of code in which something can go wrong, where should you place the block?

A) It should be placed in a try block.
B) It should be placed after a catch statement.
C) It should be prefaced with a finally statement.
D) It should be defined as an exception block.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
10
According to the creators of C#, an infrequent event in code is one that happens in less than what percent of all program executions?

A) 10%
B) 25%
C) 30%
D) 35%
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
11
A catch block can catch how many types of Exceptions?

A) An unlimited number of Exception types.
B) Only one can be caught.
C) As many as can be matched.
D) Two, after which the program ends.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
12
In C#, all exceptions are objects that are members or derived members of what specific class?

A) ApplicationException
B) Exception
C) SystemException
D) RuntimeException
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
13
What method is overridden by the Exception class in order to provide a descriptive error message and provide a user with 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 39 flashcards in this deck.
Unlock Deck
k this deck
14
An exception belonging to what specific class is thrown when an attempt is made to store an element of the wrong type within an array?

A) System.ArrayTypeMismatchException
B) System.TypeMismatch
C) System.FormatException
D) System.InvalidCastException
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
15
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 39 flashcards in this deck.
Unlock Deck
k this deck
16
What 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()
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
17
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 39 flashcards in this deck.
Unlock Deck
k this deck
18
What block can you use to ensure that input and output related files are properly closed?

A) execute
B) always
C) finally
D) default
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
19
C# has more than 100 defined Exception subclasses.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
20
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 39 flashcards in this deck.
Unlock Deck
k this deck
21
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 39 flashcards in this deck.
Unlock Deck
k this deck
22
The ApplicationException class is a sublcass of what other class?

A) SystemException
B) Exception
C) ObjectException
D) MainException
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
23
What class should you extend in order to create your own Exception that you can throw?

A) ApplicationException
B) ExceptionObject
C) SystemException
D) Object
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
24
When creating an Exception class, what is not one of the three recommended constructors needed?

A) A default constructor.
B) A constructor that takes a string message.
C) A constructor that takes a string message and an inner exception.
D) A constructor that takes a byte variable containing memory dumps.
Unlock Deck
Unlock for access to all 39 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 39 flashcards in this deck.
Unlock Deck
k this deck
26
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 39 flashcards in this deck.
Unlock Deck
k this deck
27
When you catch an Exception, what property holds a list of methods in the call stack as its value, allowing you to determine the location of the Exception?

A) StackTrace
B) CallTrace
C) MethodTrace
D) ClassTrace
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
28
The Environment.Exit() method is part of what namespace?

A) Exception
B) System
C) Quit
D) Language
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
29
Most exceptions that are used by programmers derive from three C# classes.What are those classes?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
30
What type of exception is thrown if there is an issue with file operations, such as opening, reading from, or writing to a file?

A) FileException
B) StorageException
C) FException
D) IOException
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
31
When an Exception object is thrown and multiple catch blocks are present, what happens?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
32
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 39 flashcards in this deck.
Unlock Deck
k this deck
33
When you write a method that catches an Exception, rather than handling the Exception itself, it can pass the exception to the method that called your method.What is this known as?

A) rethrowing the Exception
B) saving the Exception
C) opening the Exception
D) sideloading the Exception
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
34
Show the syntax (the general form) of a try…catch pair.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
35
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 39 flashcards in this deck.
Unlock Deck
k this deck
36
What happens when you divide a floating-point value by 0 in C#?

A) No exception occurs, and the special value Infinity is returned as the result.
B) The program will throw an exception of type System.DivideByZeroException.
C) The program will catch the exception, and return Undefined as the result.
D) The program will crash.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
37
What is the system of passing an exception through a chain of calling methods called?

A) propagating the exception
B) tracing the exception
C) stacking the exception
D) inheriting the exception
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
38
The memory location where the computer stores the list of locations to which the system must return is known by what term?

A) The method call trace.
B) The memory call pool.
C) The call stack.
D) The function call.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
39
Why might a finally block be necessary?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 39 flashcards in this deck.