Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-Id: <199910061458.JAA07139@mercury.xraylith.wisc.edu> To: trophime AT labs DOT polycnrs-gre DOT fr cc: cygwin AT sourceware DOT cygnus DOT com Subject: Re: problem with exceptions on egcs1.1.2 In-Reply-To: Your message of "Wed, 06 Oct 1999 11:32:35 BST." <37FB2543 DOT AF3F9542 AT polycnrs-gre DOT fr> Date: Wed, 06 Oct 1999 09:58:53 -0500 From: Mumit Khan On Wed, 6 Oct 1999, Christophe Trophime wrote: > 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 > #include > > #include > #include > #include > > class File_Exception{ > public : > char * filename; > char * status; > File_Exception(const char *msg) { > filename = new char [strlen(msg)+1]; > strcpy(filename, msg); > status = NULL; > }; Here's a few comments - - Please look at some existing code and try to use a reasonable style. This is quite unreadable, and I'm certainly not going to waste my time trying to decipher the bizarre indentation style used here. - Don't use _ prefix for variable names. Get the C++ standard and look up what is allowed and what is not. - Use standard C++ headers #include #include #include #include #include using namespace std; - You need to understand how memory allocation and deallocation in exception handlers work. See the C++ standard document (or a good book such as Stroustrup 3rd Edition); I suggest that you start forgetting about char* and start using `string' from C++ standard library. class File_Exception { private : string filename; string status; public : File_Exception(const char *msg) : filename (msg), status ("(null)") { } virtual ~File_Exception() { cout << "File_Exception Destructor : " << filename << " " << status << endl; }; virtual void debug_print(){ cerr << "File_Exception : " << filename << " " << status << endl; }; void set_status (const char * thestatus) { status = thestatus; }; }; And no, upgrading the compiler won't magically fix your code ;-) Please follow up to a C++ specific forum instead of to Cygwin list. Regards, Mumit -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com