delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/14/01:17:05

From: Crow_Dog AT MCI2000 DOT com (TheCrow)
Newsgroups: comp.os.msdos.djgpp
Subject: Class Exceptions? How? Please help
Reply-To: TheCrow AT Cyberdude DOT com
Message-ID: <34bc5616.22840403@news.mci2000.com>
Lines: 22
Date: Wed, 14 Jan 1998 06:09:01 GMT
NNTP-Posting-Host: usr30-dialup23.mix1.willowsprings.mci.net
NNTP-Posting-Date: Wed, 14 Jan 1998 01:09:01 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Maybe my subject was a little off but here is what I am wanting to
accomplish:

I am wanting to have something like this:

( however, this examle does not work. I get a compile error)
( but i do get it to work by explicitly declaring my exception)
( object before I throw it)

class ErrorClass
{
 private:
  char * _msg;

 public:
   ErrorClass( char *msg ) { _msg = msg }
   ~ErrorClass() {}
};

int main ()
{
 int i = 5;

 try
 {
  throw ( ErrorClass e )
 }
 catch ( ErrorClass e )
 {
  printf ( "\n caught error" );
 }
 return 0;
}
( but i do get it to work by explicitly declaring my exception)
( object before I throw it)

Is there another way to throw an exception aside from explicitly doing
 try
  {
    ErrorClass e;
    throw ( e ); 
   ...
   ...
  }
 catch (... blah blah

???

Please help.
Thank you.

- Raw text -


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