This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: EH in C (was: Re: (lack of) Thread-safe exceptions on AIX(gcc-2.95.1)
- To: Bill Tutt <rassilon at list dot org>
- Subject: Re: EH in C (was: Re: (lack of) Thread-safe exceptions on AIX(gcc-2.95.1)
- From: <llewelly at 198 dot dsl dot xmission dot com>
- Date: Tue, 1 Feb 2000 00:31:21 -0700 (MST)
- cc: gcc at gcc dot gnu dot org
On Mon, 31 Jan 2000, Bill Tutt wrote:
> > David Starner wrote:
> > Interesting. Wouldn't it be better just to add C++ exception handling,
> though?
> > It's substantially the same, but C++ EH is more general and has clear
> effects
> > with C++ EH over current implementations.
>
> Um.. C++ exception handling semantics depend on classes/structs being
> able to have destructors. Thus MS's creation of __finally. The
> difference between picking __catch vs. __except I would imagine was
> done so it was visually different from the C++ spelling as to try and
> reduce confusion as much as possible.
This is what catch(...) { throw;} is for. It works just like finally.
#include<stdio.h>
#include<stdexcept>
using std::runtime_error;
void foo()
{
throw runtime_error("Barf!");
}
void bar()
{
FILE* fp=fopen("foo","w");
try
{
foo();
}
catch(...)
{
fclose(fp);
printf("File closed.\n");
throw;
}
}
int main()
{
try
{
bar();
}
catch(...)
{
}
return(0);
}
[snip]