Deck 16: Exceptions and Templates

ملء الشاشة (f)
exit full mode
سؤال
If an exception is not caught, the program will abort execution.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
A(n) __________ is used in a function template to specify a generic data type.

A) dummy variable
B) exception
C) catch block
D) type parameter
E) None of these
سؤال
The try/catch/throw construct is able to handle only one type of exception in a try block.
سؤال
In a function template, the programmer substitutes __________ for __________.

A) parameters, data types
B) parameters, arguments
C) arguments, parameters
D) data types, parentheses
E) None of these
سؤال
An exception thrown from outside a try block will

A) be caught outside the catch block
B) be caught inside the catch block
C) remain inside the throw block
D) cause the program to abort execution
E) None of these
سؤال
A generic function that can work with any data type is called an exception template.
سؤال
Which of the following is used to signal errors or unexpected results that happen as a program runs?

A) virtual functions
B) destructors
C) exceptions
D) templates
E) None of these
سؤال
The try block of a try/catch construct is used to display the definition of an exception parameter.
سؤال
If an exception is not caught, it is stored for later use.
سؤال
When an error occurs, an exception is

A) created
B) thrown
C) passed
D) ignored
E) None of these
سؤال
Function templates allow you to write a single function definition that works with many data types.
سؤال
There is no difference between declaring an object of an ordinary class and an object of a template class.
سؤال
Using a function template requires less code than overloading a function.
سؤال
If an exception is thrown by a member function of a class object, the class __________ is called.

A) constructor
B) destructor
C) catcher
D) handler
E) None of these
سؤال
Given the following code, what will happen if the value of denom is 0?
Double divide(int numer, int denom)
{
If (denom == 0)
Throw "ERROR:
Cannot divide by zero.\n";
Else
Return static_cast(numer)/denom;
}

A) Nothing will happen because there is no catch block.
B) The program will display ERROR: Cannot divide by zero.and then move to the statement following the if/else block.
C) The program will display ERROR: Cannot divide by zero.and then halt.
D) There is no throw point because there is no try block.
E) None of these
سؤال
The line containing a throw statement is known as the throw point.
سؤال
In the following code, which statement is the throw point?
Double divide(int numer, int denom)
{
If (denom == 0)
Throw "ERROR:
Cannot divide by zero.\n";
Else
Return static_cast(numer)/denom;
}

A) if (denom == 0)
B) throw "ERROR: Cannot divide by zero.\n";
C) return static_cast(numer)/denom;
D) There is no throw point because there is no try block.
E) None of these
سؤال
Exceptions are used to signal errors or unexpected results that occur when a program is running.
سؤال
The __________ starts with the key word try and is followed by a block of code that executes any statement that might cause an exception to be thrown..

A) try block
B) try/catch class
C) try function
D) catch function
E) None of these
سؤال
A program may not contain both a "regular" version of a function and a template version of the function.
سؤال
If you want to catch a bad_alloc exception in a program, you should include

A) #include
B) #include
C) #include
D) None of these
سؤال
All type parameters defined in a function template must appear at least once in the

A) function parameter list
B) preprocessor directives
C) function call
D) type.h file
E) None of these
سؤال
Catch blocks serve as

A) exception handlers
B) receivers
C) temporary variables
D) permanent storage for trapped errors
E) None of these
سؤال
What does the T represent in the following statement?
Template < class T >

A) the name of the function template
B) T stands for Template
C) a generic data type that is used in a function template
D) the int data type
E) None of these
سؤال
When the __________ operator fails to allocate memory, C++ throws a bad_alloc exception.

A) new
B) alloc
C) catch
D) None of these
سؤال
The beginning of a function template is marked by a

A) return type
B) parameter list
C) template prefix
D) semicolon
E) None of these
سؤال
How much memory is reserved for a function template?

A) four bytes
B) It depends on the size of the template.
C) two bytes
D) no memory
E) None of these
سؤال
The try block is immediately followed by one or more

A) errors
B) error messages
C) catch blocks
D) throw blocks
E) None of these
سؤال
What does the word class indicate in the following statement?
Template < class T >

A) class is a key word that is used to precede the type parameter.
B) It indicates that a class is being derived from an existing class named T.
C) It indicates that a class named T is being derived from a class named template.
D) A class named T will automatically be created by the compiler.
E) None of these
سؤال
A generic function that can work with any data type is a

A) function argument
B) function parameter
C) function template
D) member function
E) None of these
سؤال
A(n) __________ is a value or an object that signals an error.

A) destructor
B) template
C) throw
D) exception
E) None of these
سؤال
An actual instance of the function is created in memory when the compiler encounters

A) the template prefix
B) a call to the template function
C) a try block
D) a catch block
E) None of these
سؤال
Class templates allow you to create one general version of a class without having to

A) write any code
B) use member functions
C) use private members
D) duplicate code to handle multiple data types
E) None of these
سؤال
A function template's prefix contains __________ enclosed in angle brackets.

A) one or more generic data types
B) the function definition
C) constant values
D) the function's return type
E) None of these
سؤال
A function template prefix is placed before the function header while a class template prefix is placed

A) following the public: access specification
B) following the private: access specification
C) before the class declaration
D) before the class constructor function header
E) None of these
سؤال
To handle an exception that has been thrown, a program must have a(n)

A) throw function
B) try/catch construct
C) fatal error
D) unrecoverable error
E) None of these
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/36
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 16: Exceptions and Templates
1
If an exception is not caught, the program will abort execution.
True
2
A(n) __________ is used in a function template to specify a generic data type.

A) dummy variable
B) exception
C) catch block
D) type parameter
E) None of these
D
3
The try/catch/throw construct is able to handle only one type of exception in a try block.
False
4
In a function template, the programmer substitutes __________ for __________.

A) parameters, data types
B) parameters, arguments
C) arguments, parameters
D) data types, parentheses
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
5
An exception thrown from outside a try block will

A) be caught outside the catch block
B) be caught inside the catch block
C) remain inside the throw block
D) cause the program to abort execution
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
6
A generic function that can work with any data type is called an exception template.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following is used to signal errors or unexpected results that happen as a program runs?

A) virtual functions
B) destructors
C) exceptions
D) templates
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
8
The try block of a try/catch construct is used to display the definition of an exception parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
9
If an exception is not caught, it is stored for later use.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
10
When an error occurs, an exception is

A) created
B) thrown
C) passed
D) ignored
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
11
Function templates allow you to write a single function definition that works with many data types.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
12
There is no difference between declaring an object of an ordinary class and an object of a template class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
13
Using a function template requires less code than overloading a function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
14
If an exception is thrown by a member function of a class object, the class __________ is called.

A) constructor
B) destructor
C) catcher
D) handler
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
15
Given the following code, what will happen if the value of denom is 0?
Double divide(int numer, int denom)
{
If (denom == 0)
Throw "ERROR:
Cannot divide by zero.\n";
Else
Return static_cast(numer)/denom;
}

A) Nothing will happen because there is no catch block.
B) The program will display ERROR: Cannot divide by zero.and then move to the statement following the if/else block.
C) The program will display ERROR: Cannot divide by zero.and then halt.
D) There is no throw point because there is no try block.
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
16
The line containing a throw statement is known as the throw point.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
17
In the following code, which statement is the throw point?
Double divide(int numer, int denom)
{
If (denom == 0)
Throw "ERROR:
Cannot divide by zero.\n";
Else
Return static_cast(numer)/denom;
}

A) if (denom == 0)
B) throw "ERROR: Cannot divide by zero.\n";
C) return static_cast(numer)/denom;
D) There is no throw point because there is no try block.
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
18
Exceptions are used to signal errors or unexpected results that occur when a program is running.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
19
The __________ starts with the key word try and is followed by a block of code that executes any statement that might cause an exception to be thrown..

A) try block
B) try/catch class
C) try function
D) catch function
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
20
A program may not contain both a "regular" version of a function and a template version of the function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
21
If you want to catch a bad_alloc exception in a program, you should include

A) #include
B) #include
C) #include
D) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
22
All type parameters defined in a function template must appear at least once in the

A) function parameter list
B) preprocessor directives
C) function call
D) type.h file
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
23
Catch blocks serve as

A) exception handlers
B) receivers
C) temporary variables
D) permanent storage for trapped errors
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
24
What does the T represent in the following statement?
Template < class T >

A) the name of the function template
B) T stands for Template
C) a generic data type that is used in a function template
D) the int data type
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
25
When the __________ operator fails to allocate memory, C++ throws a bad_alloc exception.

A) new
B) alloc
C) catch
D) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
26
The beginning of a function template is marked by a

A) return type
B) parameter list
C) template prefix
D) semicolon
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
27
How much memory is reserved for a function template?

A) four bytes
B) It depends on the size of the template.
C) two bytes
D) no memory
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
28
The try block is immediately followed by one or more

A) errors
B) error messages
C) catch blocks
D) throw blocks
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
29
What does the word class indicate in the following statement?
Template < class T >

A) class is a key word that is used to precede the type parameter.
B) It indicates that a class is being derived from an existing class named T.
C) It indicates that a class named T is being derived from a class named template.
D) A class named T will automatically be created by the compiler.
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
30
A generic function that can work with any data type is a

A) function argument
B) function parameter
C) function template
D) member function
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
31
A(n) __________ is a value or an object that signals an error.

A) destructor
B) template
C) throw
D) exception
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
32
An actual instance of the function is created in memory when the compiler encounters

A) the template prefix
B) a call to the template function
C) a try block
D) a catch block
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
33
Class templates allow you to create one general version of a class without having to

A) write any code
B) use member functions
C) use private members
D) duplicate code to handle multiple data types
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
34
A function template's prefix contains __________ enclosed in angle brackets.

A) one or more generic data types
B) the function definition
C) constant values
D) the function's return type
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
35
A function template prefix is placed before the function header while a class template prefix is placed

A) following the public: access specification
B) following the private: access specification
C) before the class declaration
D) before the class constructor function header
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
36
To handle an exception that has been thrown, a program must have a(n)

A) throw function
B) try/catch construct
C) fatal error
D) unrecoverable error
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 36 في هذه المجموعة.