problem with exceptions on egcs1.1.2
Christophe Trophime
trophime@labs.polycnrs-gre.fr
Wed Oct 6 02:29:00 GMT 1999
I am currently using B20.1 and egcs1.1.2. I am trying to port on NT4 a
code developped on SGI which uses exceptions.
I have some problems with exception.
I tried this simple example :
include <strings.h>
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
class File_Exception{
public :
char * filename;
char * status;
File_Exception(const char *msg) {
filename = new char [strlen(msg)+1];
strcpy(filename, msg);
status = NULL;
};
virtual ~File_Exception() {
cout << "File_Exception Destructor : " << filename << " " << status
<< endl << flush;
delete[] filename;
delete[] status;
};
virtual void debug_print(){
cerr << "File_Exception : ";
cerr << filename << " " << status;
cerr << endl << flush;
};
void set_status(const char * _thestatus){
status = new char[strlen(_thestatus)+1];
strcpy(status,_thestatus);
};
};
class File_NotFound : public File_Exception{
public :
File_NotFound(const char *msg) : File_Exception(msg) {
File_Exception::set_status("file not found");
};
};
class SimpleReader
{
protected:
char * filename;
ifstream * str;
public:
// Constructors and Destructor
SimpleReader(char * name)
{
filename = new char[strlen(name)+1];
strcpy(filename, name);
str = new ifstream(filename, ios::in|ios::nocreate);
};
virtual ~SimpleReader(){
str->close();
delete str;
delete[] filename;
};
void init(){if (str->fail()) throw File_NotFound(filename);};
};
int main(int argc, char *argv[])
{
int result = 0;
SimpleReader * psr = new SimpleReader(argv[1]);
try {
psr->init();
}
catch(File_Exception & msg){
msg.debug_print();
result=1;
}
delete psr;
return result;
}
It works fine on SGI (using either gcc 2.8.1 or Mipspro 7.20) but
it gives me the following error message with egcs1.1.2 :
File_Exception Destructor : C++_loops_elma file not found
File_Exception : ?"A
File_Exception Destructor : ?"A
[main] D:\Users\Trophime\Thelma\usr\test_exceptions.exe 2784 (0)
handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
[main] test_exceptions 2784 (0) handle_exceptions: Dumping stack trace
to test_exceptions.exe.core
The exception is deleted before it is caught by my handler which is not
the case on SGI.
Do I make something wrong?
Is there a work around to make exception working?
Or should I consider upgrade to GCC2.95?
Thanks for help.
More information about the Cygwin
mailing list