An example of C++ exceptions
Not what you're looking for?
Suppose an exception, class myException, is defined as follows:
class myException
{
public:
myException()
{
message = "myException thrown!";
cout << "Immediate attention required!"
<< endl;
}
myException (string msg)
{
message = msg;
cout << "Attention required!" << endl;
}
string what()
{
return message;
}
private:
string message;
}
Suppose that in a user program, the catch block has the following form:
catch (myException mE)
{
cout << mE.what() << endl;
}
1. What output will be produced if the exception is thrown with the default constructor?
2. What output will be produced if the exception is thrown with the constructor with parameters with the following actual parameter?
"May Day, May Day"
Purchase this Solution
Solution Summary
This solution shows an example of C++ exceptions in a couple different situations.
Solution Preview
Both constructors do two things. They both set the message and they both print a string. Setting the message doesn't cause any output but printing a string does cause a message to be printed as soon as the exception is created. The ...
Purchase this Solution
Free BrainMass Quizzes
Javscript Basics
Quiz on basics of javascript programming language.
C++ Operators
This quiz tests a student's knowledge about C++ operators.
Basic Computer Terms
We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.
Word 2010: Table of Contents
Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.
Inserting and deleting in a linked list
This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.