This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Exception Catching.
- To: "Andy Hanson" <andrew_g_hanson at yahoo dot com>
- Subject: Re: Exception Catching.
- From: Paul Bunyk <paul at pbunyk dot physics dot sunysb dot edu>
- Date: Thu, 8 Jun 2000 12:51:36 -0400 (EDT)
- Cc: gcc at gcc dot gnu dot org
- References: <001b01bfd15d$21bd21b0$0600a8c0@topguppy.ick>
See signal(2).
You can install a signal handler (your function) which will be
activated when your Sig 11 occures. You might even try to raise an
exception from within that signal handler (to be catched in your catch
block), but I'm not sure if it would work. From man page:
According to POSIX, the behaviour of a process is unde
fined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal
that was not generated by the kill() or the raise() func
tions.
Hope this helps, but what is wrong with good old way of just getting
the core file after the program crashed and look on it in debugger?
Paul
Andy Hanson writes:
> Does any version of GCC catch exceptions on things like this.
>
> void test_func(void)
> {
> long *val=NULL;
>
> ((long *)val)[0]=0xdeadcafe;
> }
>
> int main(void)
> {
> try
> {
> test_func();
> }
> catch(...)
> {
> printf("error occured\n");
> return 1;
> }
> printf("worked ok\n");
>
> return 0;
> }
>
> I'm still used to the VC++ compiler suite which allows me to catch memory
> violations like this. Under linux gcc (egcs-2.91.66 19990314/Linux
> (egcs-1.1.2 release)) I just get a segmentation fault.
>
> Is there another way to trap such a violation using gcc (under unix
> platforms)?
>
> Thanks in advance.
>
> Andy
>
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com