Mail Archives: djgpp/1997/01/15/05:10:31
From: | un1t AT rz DOT uni-karlsruhe DOT de (Matthias Baas)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | throw,catch,try problem
|
Date: | Tue, 14 Jan 1997 19:02:42 GMT
|
Organization: | University of Karlsruhe, Germany
|
Lines: | 57
|
Message-ID: | <5bgl7r$61k$1@nz12.rz.uni-karlsruhe.de>
|
NNTP-Posting-Host: | rzstud1.rz.uni-karlsruhe.de
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi,
I have a problem with the C++ exception handling mechanism supported
by djgpp V2.7.2.1. The problem occurs when I try to throw an exception
that I do not catch. Documentations tell me that in this case the
exception handling mechanism calls the terminate() function. Then
this function calls the most recent function that was given to
set_terminate().
But as I wanted to test this feature the program terminated with the
message "Abort!" and without executing my own termination function.
I used the following code:
#include <iostream.h>
void term() // my own termination function
{
cout<<"Terminate()"<<endl;
abort();
}
int main()
{
set_terminate(term);
try {
throw int(5); // just throwing anything I do not catch
}
return 0;
}
I compiled the program (called "test.cc") with:
gcc test.cc -lgpp -lstdcx -fhandle-exceptions
I also tried the same program under Linux with:
gcc bspl1.cc -lg++ -fhandle-exceptions
And here everything worked fine, the program terminated with the
message "Terminate()".
So what's wrong with djgpp or what's wrong with my code?
And why do I have to add the -lstdcx option when I use djgpp?
I assumed that the libraries on the different platforms contain at
least the same functions.
I hope someone can help...
- Matthias -
PS: Looking at the file sizes of the DOS- and Linux executables of
the above program made me a bit uneasy. I stripped both files,
but while the Linux file shrinked to a handsome 5KB file, the
DOS executable still needs about 100KB !
Is there a reasonable explanation for this?
I was just wondering...
- Raw text -