home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
EXCEPTIO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-28
|
775b
|
35 lines
#include <iostream.h>
#include <stdexcept>
using namespace std;
#ifdef RWSTD_NO_EXCEPTIONS
int main ()
{
cout << "Your compiler doesn't support exceptions!" << endl;
return 0;
}
#else
static void f() { throw runtime_error("a runtime error"); }
int main ()
{
//
// By wrapping the body of main in a try-catch block we can be
// assured that we'll catch all exceptions in the exception hierarchy.
// You can simply catch exception as is done below, or you can catch
// each of the exceptions in which you have an interest.
//
try
{
f();
}
catch (const exception& e)
{
cout << "Got an exception: " << e.what() << endl;
}
return 0;
}
#endif /*RWSTD_NO_EXCEPTIONS*/