delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/20/09:48:10

Message-ID: <39F04CBB.1B907DFC@alpha.delta.edu>
Date: Fri, 20 Oct 2000 09:46:35 -0400
From: "David Witbrodt" <dawitbro AT alpha DOT delta DOT edu>
X-Mailer: Mozilla 4.73 [en] (Win98; U)
X-Accept-Language: en,ja
MIME-Version: 1.0
To: DJGPP mailing list <djgpp AT delorie DOT com>
Subject: Exceptions support
Reply-To: djgpp AT delorie DOT com

Can anyone explain to me why PROG1 works, but PROG2 dies?  (Both work
fine with Visual C++.)

// PROG1.CPP
#include <iostream.h>

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 <iostream.h>

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019