1// Build don't link: 2// Special g++ Options: -fexceptions 3// GROUPS passed exceptions 4// except file 5// Message-Id: <199311101607.AA11803@hsi86.hsi.com> 6// From: Grigory Tsipenyuk <grigory@hsi.com> 7// Subject: exception's bug? 8// Date: Wed, 10 Nov 1993 11:07:12 -0500 9 10#include <iostream> 11 12class X { 13 int *a; 14 int sz; 15public: 16 class range { }; // exception class 17 X(int s) { a=new int[sz=s]; } 18 int& operator[](int i); 19}; 20 21int& X::operator[](int i) 22{ 23 if (i < 0 || i >= sz) { 24 throw range(); 25 } 26 return a[i]; 27} 28 29int 30main() 31{ 32 X c(10); 33 try { 34 for (int i = 0; i < 12; i++) 35 c[i] = 1; 36 } catch (X::range) { 37 std::cerr << "invalid range\n"; 38 } 39 return 0; 40} 41