source: branches/libc-0.6/testcase/throw-2.cpp

Last change on this file 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
Line 
1// exceptions: multiple catch blocks
2#include <iostream>
3using namespace std;
4
5int 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.