From: pavenis AT lanet DOT lv To: "David Witbrodt" , djgpp AT delorie DOT com Date: Fri, 20 Oct 2000 17:44:50 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Exceptions support Message-ID: <39F08492.17178.103C4D8@localhost> In-reply-to: <39F04CBB.1B907DFC@alpha.delta.edu> X-mailer: Pegasus Mail for Win32 (v3.12c) Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Try this: #include void PrList (int stopval) { int x = 1; while (1) { if (x >= stopval) throw "Out of bounds"; cout << x++ << endl; } } int main (void) { try { PrList (10); } catch (char *msg) { cout << "char* catched: " << msg << endl; } catch (const char *msg) { cout << "const char* catched: " << msg << endl; } return 0; } and You'll see the source of problem ... Andris On 20 Oct 2000, at 9:46, David Witbrodt wrote: > Can anyone explain to me why PROG1 works, but PROG2 dies? (Both work > fine with Visual C++.) > > // PROG1.CPP > #include > > void PrList (int stopval) > { int x = 1; > while (1) > { if (x >= stopval) throw x; > cout << x++ << endl; > } > } > > int main (void) > { try { PrList (10); } > catch (int n) { cout << "Exception at " << n << endl; } > return 0; > } > > > // PROG2.CPP > #include > > void PrList (int stopval) > { int x = 1; > while (1) > { if (x >= stopval) throw "Out of bounds"; > cout << x++ << endl; > } > } > > int main (void) > { try { PrList (10); } > catch (char *msg) { cout << msg << endl; } > return 0; > } > > > Thanks, > Dave W. > -- > "... for if leisure and security were enjoyed by all alike, the great > mass of human beings ... would learn to think for themselves; and when > once they had done this, they would sooner or later realize that the > privileged minority had no function, and they would sweep it away." - > Emmanuel Goldstein >