1.
True or false: exceptions may be generated by the runtime or by user-defined code.
True False
The CLR generates exceptions for conditions such as array index out of bounds, out of memory,
null reference, etc. User code can generate an exception using the throw keyword.
2.
Which construct is used to handle exceptions that might be raised within a certain
section of code?
try/catch try/finally
A catch block is used to handle exceptions raised within the associated try
block.
3.
Which construct is used to ensure that a certain section of code always runs whenever execution
leaves a designated piece of code, whether due to an exception or not?
try/catch try/finally
A finally block is used to ensure execution of a section of code regardless of how the
associated try block is exited.
4.
True or false: more than one catch handler can be specified for the same
try block.
True False
Multiple catch blocks are allowed for a single try block. When an
exception is generated, the handlers are evaluated in textual order and only the first matching
handler is executed.
5.
True or false: the catch and finally constructs may be associated
with the same try block.
True False
A try block can be followed by multiple catch blocks and then an optional
finally block.
6.
True or false: the CLR allows custom exceptions to be defined.
True False
Custom exception types can be defined by creating a class that inherits from a standard library
exception class. Technically, the custom exception only needs to be derived from the
Exception class; however, there is a class called ApplicationException
that exists to serve as the base class for custom exception types.