Re: Catching FP division by 0?

Discussion in 'C++' started by Ioannis Vranos, Mar 28, 2005.

  1. Actually from another thread I remembered that one can use SIGFPE of <csignal> to handle a
    division by zero:

    "SIGFPE an erroneous arithmetic operation, such as zero divide or an operation resulting
    in overflow".



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Mar 28, 2005
    #1
    1. Advertising

  2. Ioannis Vranos wrote:
    >
    > Actually from another thread I remembered that one can use SIGFPE of
    > <csignal> to handle a division by zero:
    >
    > "SIGFPE an erroneous arithmetic operation, such as zero divide or an
    > operation resulting in overflow".



    But then again, SIGFPE handling does not work in my system. But then the standard says:

    "An implementation need not generate any of these signals, except as
    a result of explicit calls to the raise function."


    raise() indeed works:


    #include <iostream>
    #include <csignal>


    void sigfpe_handler(int sig)
    {
    std::cerr << "An erroneous arithmetic operation just occurred!\n";
    }


    int main ()
    {
    using namespace std;

    signal(SIGFPE, sigfpe_handler);

    raise(SIGFPE);
    }



    C:\c>temp
    An erroneous arithmetic operation just occurred!

    C:\c>


    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Mar 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    12
    Views:
    1,859
  2. sunwij

    FLOATING POINT DIVISION

    sunwij, Dec 28, 2003, in forum: VHDL
    Replies:
    3
    Views:
    1,014
    sunwij
    Dec 29, 2003
  3. Manfred Balik

    polynomial division remainder

    Manfred Balik, May 12, 2004, in forum: VHDL
    Replies:
    5
    Views:
    3,294
    Mike Treseler
    May 18, 2004
  4. BigMan

    Catching FP division by 0?

    BigMan, Mar 16, 2005, in forum: C++
    Replies:
    20
    Views:
    803
    falcon
    Mar 19, 2005
  5. Replies:
    94
    Views:
    4,392
    ┬Ča\\/b
    Feb 9, 2007
Loading...

Share This Page