divide by zero exception

divide by zero exception

Post by KenThorp » Fri, 23 Jul 1999 04:00:00



My question is how can I catch a generic exception in C++ without
being redirected to a signal handler. For example

I want the following code to work.

  try
  {
      x = x / 0; // or
      ptr = NULL;
      ptr->data;
  }
  catch(...)
  {
    // handle the error.
  }

I would like both of these items to be caught with
the exception handler instead of a signal handler.
When I compile gcc +eh exception handling works for
thrown exceptions but not for the exceptions described above.

Thanks
Ken

 
 
 

divide by zero exception

Post by John F Ca » Sat, 24 Jul 1999 04:00:00




>My question is how can I catch a generic exception in C++ without
>being redirected to a signal handler.

C++ exception handlers can't catch signals and signal handlers can't
throw exceptions.  You have to write the zero check code yourself.
This is a basic design choice of C++ allowing for simpler and more
efficient implementations; some other languages (e.g. Ada and Java)
make the opposite choice and can do what you want.

Quote:>  try
>  {
>      x = x / 0; // or
>      ptr = NULL;
>      ptr->data;
>  }
>  catch(...)
>  {
>    // handle the error.
>  }

--


 
 
 

1. New: Divide by zero (/proc/sys/net/ipv4/neigh/DEV/base_reachable_time)

http://bugme.osdl.org/show_bug.cgi?id=420

           Summary: Divide by zero
                    (/proc/sys/net/ipv4/neigh/DEV/base_reachable_time)
    Kernel Version: 2.4.20, 2.5.63
            Status: NEW
          Severity: normal


Distribution:Debian GNU/Linux 3.0, Vine Linux 2.6
Hardware Environment:
Software Environment:
Problem Description:
  Divide by zero (/proc/sys/net/ipv4/neigh/DEV/base_reachable_time)
Steps to reproduce:
  I found the problem of neigh_rand_reach_time() in net/core/neighbour.c.
  This function called by neigh_periodic_timer() each 300 seconds,
  and argument of neigh_periodic_timer() is p->base_reachable_time.
  base_reachable_time can set to 0 by below sequence.

    echo 0 > /proc/sys/net/ipv4/neigh/DEV/base_reachable_time

  But neigh_rand_reach_time() divide by its argument.

    unsigned long neigh_rand_reach_time(unsigned long base)
    {
        return (net_random() % base) + (base>>1);
    }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Solaris 7 on Compaq AP400

3. catching integer divide by zero in C code

4. Caldera font server in Slackware

5. divide by zero / segmentation fault

6. deadlock in 2.5.62 drivers/usb/host/uhci-hcd.c?

7. sched: integer divide zero trap:

8. renaming files

9. WABI 2.0 divide-by-zero Error?

10. Linux Divide by zero error when running "ps u" 1.3.77

11. Divide by zero error on bootup?!

12. Divide by Zero trapping

13. Floppy reports size as zero sectors, zero tracks, zero bytes