X
xuatla
Hi,
I tried the following code about try/catch (from cplusplus.com)
// exceptions
#include <ciostream>
using namespace std;
int main () {
char myarray[10];
try
{
for (int n=0; n<=10; n++)
{
if (n>9) throw "Out of range";
myarray[n]='z';
}
}
catch (char * str)
{
cout << "Exception: " << str << endl;
}
return 0;
}
It's expected to give "Exception: Out of range".
but i complied in g++ 3.3.3. and run it, the output is "Aborted".
Anyone help me to explain what's wrong here? or normal?
Thanks a lot!
xuatla
I tried the following code about try/catch (from cplusplus.com)
// exceptions
#include <ciostream>
using namespace std;
int main () {
char myarray[10];
try
{
for (int n=0; n<=10; n++)
{
if (n>9) throw "Out of range";
myarray[n]='z';
}
}
catch (char * str)
{
cout << "Exception: " << str << endl;
}
return 0;
}
It's expected to give "Exception: Out of range".
but i complied in g++ 3.3.3. and run it, the output is "Aborted".
Anyone help me to explain what's wrong here? or normal?
Thanks a lot!
xuatla