public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Exception Catching.
@ 2000-06-08  9:06 Andy Hanson
  2000-06-08  9:46 ` Paul Bunyk
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Hanson @ 2000-06-08  9:06 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Exception Catching.
  2000-06-08  9:06 Exception Catching Andy Hanson
@ 2000-06-08  9:46 ` Paul Bunyk
  2000-06-08 10:57   ` Andy Hanson
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Bunyk @ 2000-06-08  9:46 UTC (permalink / raw)
  To: Andy Hanson; +Cc: gcc

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1540 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Exception Catching.
  2000-06-08  9:46 ` Paul Bunyk
@ 2000-06-08 10:57   ` Andy Hanson
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Hanson @ 2000-06-08 10:57 UTC (permalink / raw)
  To: Paul Bunyk; +Cc: gcc

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2453 bytes --]

Yeah, I knew how to get the signal from SIGSEGV, the problem is that once
inside the signal handler, if I do a throw, it does not ever get caught by
the catch.  So I cannot gracefully clean up after myself.

Currently my headache is that if I have an unfound bug that crashes my
program, I need to do some database cleanup work, before I exit.  Some of
the data needed to clean up the database was created on the stack and is not
accessible from inside the signal handler without a fairly major hack.

It isn't really a debug problem, but a cleanup problem.

Andy

----- Original Message -----
From: Paul Bunyk <paul@pbunyk.physics.sunysb.edu>
To: Andy Hanson <andrew_g_hanson@yahoo.com>
Cc: <gcc@gcc.gnu.org>
Sent: Thursday, June 08, 2000 11:51 AM
Subject: Re: Exception Catching.



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


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Exception Catching.
@ 2000-06-08 13:54 Mike Stump
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Stump @ 2000-06-08 13:54 UTC (permalink / raw)
  To: andrew_g_hanson, paul; +Cc: gcc

> X-Apparently-From: <andrew?g?hanson@yahoo.com>
> From: "Andy Hanson" <andrew_g_hanson@yahoo.com>
> To: "Paul Bunyk" <paul@pbunyk.physics.sunysb.edu>
> Cc: <gcc@gcc.gnu.org>
> Date: Thu, 8 Jun 2000 12:00:10 -0500

> Yeah, I knew how to get the signal from SIGSEGV, the problem is that once
> inside the signal handler, if I do a throw, it does not ever get caught by
> the catch.  So I cannot gracefully clean up after myself.

sjlj-exceptions will just work in this case.  If you want dwarf to
work, you must arrange for information about the frame to be visible
to EH.  One way would be to have the OS add a catch clause around the
signal handler that does the right think, another would be for you to
figure out the description for the frame yourself, and add that to gcc.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Exception Catching.
@ 2000-06-08 13:47 Mike Stump
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Stump @ 2000-06-08 13:47 UTC (permalink / raw)
  To: andrew_g_hanson, gcc

What you want to do isn't portable.  You can catch them via signal.
See man signal.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-06-08 13:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-08  9:06 Exception Catching Andy Hanson
2000-06-08  9:46 ` Paul Bunyk
2000-06-08 10:57   ` Andy Hanson
2000-06-08 13:47 Mike Stump
2000-06-08 13:54 Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).