Download Special Edition Using Visual C++ 6
Transcript
Special Edition Using Visual C++ 6 -- Ch 26 -- Exceptions and Templates
general as you can get, catching every single exception that the program throws. In this case
(as in most cases), you want to use catch(...) to receive only the leftover exceptions.
Listing 26.6 EXCEPTION6.CPP--Using Multiple catch Blocks
#include <iostream.h>
class MyException
{
protected:
char* m_msg;
public:
MyException(char *msg) { m_msg = msg;}
~MyException(){}
char* GetError() {return m_msg;}
};
int GetValue();
int main()
{
try
{
int value = GetValue();
cout << "The value you entered is okay." << endl;
}
catch(MyException* exception)
{
char* msg = exception->GetError();
cout << msg << endl;
}
catch(char* msg)
{
cout << msg << endl;
}
catch(...)
{
cout << "Caught unknown exception!" << endl;
}
return 0;
}
int GetValue(){
int value;
cout << "Type a number from 4 to 8 (except 6):" << endl;
cin >> value;
if (value < 4)
{
MyException* exception =
http://www.pbs.mcp.com/ebooks/0789715392/ch26/ch26.htm (10 of 23) [7/29/1999 3:57:14 PM]
Related documents
Oracle Health Insurance Back Office
PDF file - EMME/2 Support Center
IMK-571R Software and Programming Guides
General Terms and Conditions for bank accounts and payment
coen-2003-project-24.. - Computer Engineering
User Guide
User manual - UK Free TV
Cortex-M3 107 Development Board User`s Manual
WinCON - Getting Started Manual
KALOS 2 USER MANUAL
WinCon-8000 Getting Started
Visual C++ 6.0 Tutorial