Re: gcc exception handle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, extern "C" { class A { public: private: char string[SIZE]; }; void test1(void) { A obj; try { throw obj; } catch (A &e) { printf(" exception ! \n "); } } }//extern "C" when I define "obj" as a global variable ,static variable or dynamic variable(allocate space with "malloc") ,there is no error occured;but when I define "obj" as a local variable in stack area,program will crash.

Is the reason that the size of variable "obj" is bigger than the stack size?
Does the setjmp/longjmp exception handling mechanism have bugs ?

My gcc version is gcc4.1.1 and my compiler is a cross compiler with TARGET=sh-elf,HOST=i686-pc-cygwin,BUILD=i686-pc-cygwin.

expecting your answer.

--David

From: Andrew Haley <aph@xxxxxxxxxx>
To: 王 刚伟 <gwwang10@xxxxxxxxxxx>
CC: gcc-help@xxxxxxxxxxx
Subject: Re: gcc exception handle
Date: Mon, 29 Jan 2007 11:11:36 +0000

?瞻 writes:
 > Hi,
 >
 > Here is My test function :
 >
 > class A
 > {
 > public:
 > private:
 >  char string[SIZE];
 > };
 >
 > void test1(void)
 > {
 >     A obj;
 >
 >     try
 >     {
 >        throw obj;
 >     }
 >     catch (A &e)
 >     {
 >        printf("exception ! \n");
 >     }
 > }
 >
 > when SIZE <= 68,"__cxa_allocate_exception" allocates space for the
> exception successfully,after "__cxa_throw" is
called,"__cxa_begin_catch" is
> called,and the statement "printf..." in the catch block can be
executed.
> when SIZE > 68, ,"__cxa_allocate_exception" also allocates space for
the
> exception successfully,but after "__cxz_throw" is
called,"__cxa_end_catch"
 > is called,and the program crashed.

Works for me.  What arch, what compiler version, etc.

Andrew.

_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux