Topic: What exceptions behaviour is standard?
Author: andyk@victory.rosnet.ru
Date: 1998/09/24 Raw View
The following code produces different results on
SunPro CC 4.2, egcs 1.1b and SunPro CC 5.0:
Program output on SunPro CC 4.2 and egcs 1.1b
_____________________________________________
start
Out of mem
catched
_____________________________________________
Program output on SunPro CC 5.0
_____________________________________________
start
_____________________________________________
and the program is hanged up
So, what behaviour is ANSI standard? Or where is the bug?
CODE:
_____________________________________________
#include <new.h>
#include <iostream.h>
class OutofMemory {
public:
OutofMemory(){cout<<"Out of mem\n";};
};
class M
{
public:
M (char *name, const short rows, const short cols);
const short Rows (void) {return rows;}
const short Cols (void) {return cols;}
char *name;
private:
const short rows;
const short cols;
double *elems;
};
M::M (char *name_, const short r, const short c) : name(name_),
rows(r), cols(c)
{
try { elems = new double[rows * cols]; }
catch (...) { throw OutofMemory(); }
}
main ()
{
cout<<"start"<<endl;
try {
M m("m",20000L,30000L);
}
catch (OutofMemory) {
cout<<"catched"<<endl;
}
}
_____________________________________________________________________
Andrew Kolessa
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Andrew A. Kolessa" <andyk@victory.rosnet.ru>
Date: 1998/09/23 Raw View
The following code produces different results on
SunPro CC 4.2, egcs 1.1b and SunPro CC 5.0:
Program output on SunPro CC 4.2 and egcs 1.1b
_____________________________________________
start
Out of mem
catched
_____________________________________________
Program output on SunPro CC 5.0
_____________________________________________
start
_____________________________________________
and the program is hanged up
So, what behaviour is ANSI standard? Or where is the bug?
CODE:
_____________________________________________
#include <new.h>
#include <iostream.h>
class OutofMemory {
public:
OutofMemory(){cout<<"Out of mem\n";};
};
class M
{
public:
M (char *name, const short rows, const short cols);
const short Rows (void) {return rows;}
const short Cols (void) {return cols;}
char *name;
private:
const short rows;
const short cols;
double *elems;
};
M::M (char *name_, const short r, const short c) : name(name_),
rows(r), cols(c)
{
try { elems = new double[rows * cols]; }
catch (...) { throw OutofMemory(); }
}
main ()
{
cout<<"start"<<endl;
try {
M m("m",20000L,30000L);
}
catch (OutofMemory) {
cout<<"catched"<<endl;
}
}
_____________________________________________________________________
Andrew Kolessa
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/09/23 Raw View
"Andrew A. Kolessa" <andyk@victory.rosnet.ru> writes:
>The following code produces different results on
>SunPro CC 4.2, egcs 1.1b and SunPro CC 5.0:
>Program output on SunPro CC 4.2 and egcs 1.1b
>_____________________________________________
>start
>Out of mem
>catched
>_____________________________________________
>Program output on SunPro CC 5.0
>_____________________________________________
>start
>_____________________________________________
>and the program is hanged up
The 5.0 compiler in question is a pre-release snapshot.
A later shapshot reports out of memory and does not hang.
--
Steve Clamage, stephen.clamage@sun.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]