This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: problem with exceptions on egcs1.1.2


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@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]