Mail Archives: djgpp/2000/07/18/21:46:05
From: | "Betelgeuse" <iam@[removethis]cadvision.com>
|
Newsgroups: | comp.os.msdos.djgpp
|
References: | <0519f96f DOT 5fb31bd3 AT usw-ex0104-033 DOT remarq DOT com>
|
Subject: | Re: Exception Handling
|
Date: | Tue, 18 Jul 2000 19:31:07 -0700
|
Lines: | 89
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.50.4133.2400
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400
|
NNTP-Posting-Host: | 207.148.139.92
|
X-Original-NNTP-Posting-Host: | 207.148.139.92
|
Message-ID: | <397506f6_7@news.cadvision.com>
|
X-Trace: | 18 Jul 2000 19:40:06 -0700, 207.148.139.92
|
Organization: | CADVision Development Corporation (http://www.cadvision.com/)
|
X-Original-NNTP-Posting-Host: | 204.50.1.43
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hawdy pardna!
:)
I believe strcpy() requires a pre-initialized destination, i.e.,
char *exception::errorMessage;
should perhaps be
char exception::errorMessage[256];
or, have your constructor do the initialization:
exception::exception()
{
errorMessage = new char[256];
}
exception::~exception()
{
delete[] errorMessage;
}
There is also strdup() which might be more suited to this, for example:
exception(char *message)
{
strcpy(errorMessage, message);
errorMessage = strdup(message);
}
I haven't worked with exceptions as I haven't found the need yet. Anyway,
hope that helps
- Betelgeuse
"Dogansmoobs" <dogansmoobsNOdoSPAM AT hotmail DOT com DOT invalid> wrote in message
news:0519f96f DOT 5fb31bd3 AT usw-ex0104-033 DOT remarq DOT com...
> I am having a problem with exception handling. Whenever I try
> to cathch and exception, instead of running what's in the catch
> block, it exits the program and displays Abort!!. Is there
> something I'm missing, or doing wrong?? Here's what I'm doing:
>
> #include <iosteam>
>
> class exception
> {
> public:
> exception(char *message)
> {
> strcpy(errorMessage, message);
> }
>
> void display()
> {
> cout << errorMessage;
> }
>
> private:
> char *errorMessage;
> };
>
> Then whin I want to throw an exception, I say:
> throw exception("Error message here");
>
> and then catch it using:
> catch (exception &e)
>
> but it never does this, it just aborts. And yes, the code that
> produces the exception is in a try block.
>
> - Dogansmoobs
> http://wookie.freehosting.net/
> I would call myself Duncan Blownuts, but people might think I'm
> insane.
>
>
> -----------------------------------------------------------
>
> Got questions? Get answers over the phone at Keen.com.
> Up to 100 minutes free!
> http://www.keen.com
>
- Raw text -