delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/10/06/11:00:28

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
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 <khan AT thor DOT xraylith DOT wisc DOT edu>

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 <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;
>         };


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 <cstring>
      #include <cstdlib>

      #include <iostream>
      #include <iomanip>
      #include <fsstream>

      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

- Raw text -


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