Last change
on this file since 2459 was 1548, checked in by bird, 21 years ago |
..
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
668 bytes
|
Rev | Line | |
---|
[1548] | 1 | // exceptions: multiple catch blocks
|
---|
| 2 | #include <iostream>
|
---|
| 3 | using namespace std;
|
---|
| 4 |
|
---|
| 5 | int main ()
|
---|
| 6 | {
|
---|
| 7 | cout << "Hello! This has to throw an exception." << endl;
|
---|
| 8 | try
|
---|
| 9 | {
|
---|
| 10 | char * mystring;
|
---|
| 11 | mystring = new char [10];
|
---|
| 12 | if (mystring == NULL)
|
---|
| 13 | throw "Allocation failure";
|
---|
| 14 | for (int n = 0; n <= 100; n++)
|
---|
| 15 | {
|
---|
| 16 | if (n > 9)
|
---|
| 17 | throw n;
|
---|
| 18 | mystring[n] = 'z';
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | catch (int i)
|
---|
| 22 | {
|
---|
| 23 | cout << "Exception: ";
|
---|
| 24 | cout << "index " << i << " is out of range" << endl;
|
---|
| 25 | }
|
---|
| 26 | catch (const char * str)
|
---|
| 27 | {
|
---|
| 28 | cout << "Exception: " << str << endl;
|
---|
| 29 | }
|
---|
| 30 | return 0;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.