• Home
  • Textbooks
  • Microsoft Visual C# 2017: An Introduction to Object-Oriented Programming
  • Exception Handling

Microsoft Visual C# 2017: An Introduction to Object-Oriented Programming

Joyce Farrell

Chapter 11

Exception Handling - all with Video Answers

Educators


Chapter Questions

03:06

Problem 1

Any error condition or unexpected behavior in an executing program is known as an ____________
a. exclusion
c. exception
b. anomaly
d. omission

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
04:27

Problem 2

Which of the following is not treated as a C\# Exception?
a. Your program asks the user to input a number, but the user enters a character.
b. You calculate a value that is too large for the answer's variable type.
c. You attempt to access an array with a subscript that is too large.
d. You attempt to execute a C\# program, but the C\# compiler has not been installed.

Rashmi Sinha
Rashmi Sinha
Numerade Educator
00:47

Problem 3

Most exceptions you will use derive from three classes: ____________ .
a. Object, ObjectException, and ObjectApplicationException
b. Exception, SystemException, and ApplicationException
c. FormatException, ApplicationException, and IOException
d. SystemException, IOException, and FormatException

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator

Problem 4

Exception objects can be ____________
a. generated automatically by $\mathrm{C \#}$
c. both of these
b. created by a program
d. none of these

Check back soon!
02:43

Problem 5

When a program creates an Exception object, you ____________ -
a. must handle it
b. can handle it
c. must not handle it
d. none of these; programs cannot create Exceptions

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator

Problem 6

If you do not use object-oriented techniques, ____________
a. you can still manage error situations
b. you cannot manage error situations
c. you can manage error situations but with great difficulty
d. error situations will seldom occur

Check back soon!

Problem 7

In object-oriented terminology, you ____________ a procedure that might not complete correctly.
a. circumvent
c. catch
b. try
d. throw

Check back soon!

Problem 8

In object-oriented terminology, a method that detects an error condition ____________ an exception.
a. throws
c. tries
b. catches
d. unearths

Check back soon!

Problem 9

When you write a block of code in which something can go wrong, and you want to throw an exception if it does, you place the code in a $\qquad$ block.
a. catch
c. system
b. blind
d. try

Check back soon!
01:21

Problem 10

A catch block executes when its try block ____________
a. completes
b. throws any Exception object
c. throws an Exception of an acceptable type
d. completes without throwing anything

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:21

Problem 11

Which of the following catch blocks will catch any Exception object?
a. catch(Any e) \{\}
b. catch(Exception e) \{\}
c. catch(e) \{\}
d. All of the above will catch any Exception.

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
00:39

Problem 12

Which of the following is valid within a catch block with the header catch(Exception error)?
a. WriteLine(error.ToString());
b. WriteLine(error.Message);
c. return(error.ToString());
d. two of these

Ernest Castorena
Ernest Castorena
Numerade Educator
07:44

Problem 13

You can place ____________ statement(s) within a try block.
a. zero
c. two
b. one
d. any number of

Samuel Goyette
Samuel Goyette
Numerade Educator

Problem 14

How many catch blocks might follow a try block within the same method?
a. only one
b. any number as long as it is greater than zero
c. any number as long as it is greater than one
d. any number, including zero or one

Check back soon!
02:13

Problem 15

Consider the following try block. If $x$ is 15 , what is the value of a when this code completes?
```
try
{
a = 99;
if(x>>)
throw(new Exception());
a = 0;
++a;
}
```
a. 0
c. 99
b. 1
d. undefined

James Kiss
James Kiss
Numerade Educator
00:57

Problem 16

Consider the following catch blocks. The variable $b$ has been initialized to 0 . If a DivideByZeroException occurs in a try block just before this catch block, what is the value of $b$ when this code completes?
```
catch(DivideByZeroException e)
{
++b;
}
catch(Exception e)
{
++b;
}
```
a. 0
c. 2
b. 1
d. 3

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
00:55

Problem 17

Consider the following catch blocks. The variable $c$ has been initialized to 0 . If an IndexOut0fRangeException occurs in a try block just before this catch block, what is the value of $c$ when this code completes?
```
catch(IndexOutOfRangeException e)
{
++c;
}
catch(Exception e)
{
++C;
}
finally
{
}
++C;
```
a. 0
c. 2
b. 1
d. 3

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:01

Problem 18

If your program throws an IndexOutOfRangeException, and the only available catch block catches an Exception, ____________ .
a. an IndexOut0fRangeException catch block is generated automatically
b. the Exception catch block executes
c. the Exception catch block is bypassed
d. the IndexOut0fRangeException is thrown to the operating system

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator

Problem 19

When you design your own classes that might cause exceptions, and other classes will use your classes as clients, you should usually create your methods to ____________
a. neither throw nor handle exceptions
b. throw exceptions but not handle them
c. handle exceptions but not throw them
d. both throw and handle exceptions

Check back soon!
00:47

Problem 20

When you create an Exception subclass of your own, you should extend the ____________ class.
a. SystemException
c. OverloadedException
b. Persona1Exception
d. Exception

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator