delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/10/16:15:35

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Jesper Lund" <jl1204 AT worldonline DOT dk>
Newsgroups: comp.os.msdos.djgpp
References: <3C66CA98 DOT 70901 AT vif DOT com>
Subject: Re: c++ exceptions
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700
Message-ID: <xjB98.4723$5L3.298693@news010.worldonline.dk>
Date: Sun, 10 Feb 2002 22:07:10 +0100
NNTP-Posting-Host: 213.237.2.159
X-Complaints-To: news-abuse AT wol DOT dk
X-Trace: news010.worldonline.dk 1013375325 213.237.2.159 (Sun, 10 Feb 2002 22:08:45 MET)
NNTP-Posting-Date: Sun, 10 Feb 2002 22:08:45 MET
Organization: Customer of Tiscali A/S (World Online)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Sahab Yazdani" <sahaby AT vif DOT com> wrote:

> does GCC3.0.x support C++ exceptions properly??  or is it that I can't
> code them properly??
>
> I have this code (stripped down for newsgroups):
> namespace Std {
>   class Exception {
>   public:
>    char *message;
>    Exception( char *message = NULL ); // this code works file!
>   };

You have to define the constructor somewhere, so this piece of code does not
link properly. Your constructor should allocate memory for the char* message
class member, and copy the string in the argument of the constructor (you
need to give that argument a different name; right now it coincides with the
class member).

[snip]

>
> NOW by my logic, this primitive program should output:
> File not found
>
> but it outputs nothing, yet if I change the line "printf( e.message);"
> to "printf( "Exception Caught: %s\n", e.message );", it outputs:
> Exception Caught:
> so it is catching the exceptions properly, but the values in the
> exception class is getting messed up.
>

The value of the e.message char pointer is 0, so printf outputs an empty
string. This is to be expected since you never assign anything to the
variable.



- Raw text -


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