Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Exception can be of only built-In type - Exception Handling
Home
>>
Category
>>
C++ (MCQ) questions and answers
>>
Exception Handling
Q. An exception can be of only built-In type.
- Published on 19 Oct 15
a.
True
b.
False
ANSWER: False
Related Content
Constructor and Destructor (
10
)
Operator Overloading (
11
)
Inheritance (
16
)
Polymorphism and Abstract Classes (
12
)
C++ basic concepts (
39
)
Exception Handling (
22
)
File Handling (
11
)
Functions (
20
)
Memory Management (
6
)
Pointers (
3
)
Discussion
Raj
-Posted on 12 Oct 15
An exception can be of only built-In type is false statement.
You can create user-defined exceptions. C++ provides a base class for all exception named as Exception. If you want to create your own exception then you have to inherit this class.
class myException : public exception{
public:
const char * what() const throw()
{
return "Divide By Zero Exception occured\n";
}
};
int main()
{
try
{
int a, b;
cout << "Enter two numbers : ";
cin >> a >> b;
if (b == 0)
{
myException exp;
throw exp;
}
else
{
cout << "a / b = " << a/b << endl;
}
}
catch(exception& eObj)
{
cout << eObj.what();
}
}
Exception class provide what() public method and it should be overridden by all the child exception classes.
➨
Post your comment / Share knowledge
Required!
Required!
Invalid Email Id!
Required!
Enter the code shown above:
Please enter the code shown above
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
MCQs
English
Tutorials
Download
▲