<---- template headericclude ----->
Fedora 11, g++ exception handling
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Location
    Switzerland
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Fedora 11, g++ exception handling

    Hi,

    Here is a simple peace of code that came from an exercise book about C++.

    I am at the exception chapter of my C++ book.

    =======================================
    #include <iostream>
    using namespace std;

    const int DefaultSize = 10;

    int main ()
    {
    int top = 90;
    int bottom = 0;

    try
    {
    cout << "top / 2 = " << (top / 2) << endl;

    cout << "top divided by bottom = ";
    cout << (top / bottom) << endl;

    cout << "top / 3 = " << (top / 3) << endl;
    }
    catch (...)
    {
    cout << "something has gone wrong!" << endl << flush;
    }

    cout << "Done." << endl;
    return 0;
    }

    =======================================

    Here is my g++ setup has installed on my system.

    [RLe@LinuxFed11 ~]$ g++ -v
    Utilisation des specs internes.
    Target: x86_64-redhat-linux
    Configuré avec: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i586 --build=x86_64-redhat-linux
    Modèle de thread: posix
    gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)

    =======================================

    Using a plain empty exception class and manual making a throw, works!

    It might be possible that the (top / bottom) operation is using deep library like calls that aren't unwinding the exceptions.
    Which bring me to think about the "--disable-libunwind-exceptions" parameter about.
    Am I on the right track?

    I finaly got gdb to work under Eclipse. One of my sub directory in the working path was named: "Listing and Exercises", look like that Eclipse wasn't providing a proper working directory to gdb.
    I wasn't able to debug until renaming it to "ListExerPjt".
    The debug session is showing an exception : "signal SIGFPE".

    The question is why the exception isn't caught by the try-catch C++ mechanism in that context?

    Regards,
    RL
    Last edited by EmbeddedTwix; 8th September 2009 at 08:46 PM. Reason: Additional details and findnigs

  2. #2
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    5,073
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your program doesn't catch the exception because no exception is thrown by a division by zero. See: http://www.jdl.co.uk/briefings/divByZeroInCpp.html
    Linux signals (like SIGFPE) aren't C++ exceptions either. They have their own handler system.

  3. #3
    Join Date
    Aug 2009
    Location
    Switzerland
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Markkuk,

    Thanks for the answer.

    My C++ book is that bad!

    Regards,
    RL

Similar Threads

  1. Fedora Fred - Handling Kernel Updates.
    By alfz in forum Installation, Upgrades and Live Media
    Replies: 5
    Last Post: 7th September 2009, 07:56 PM
  2. Anaconda exception with Fedora 11 DVD
    By calibre97 in forum Installation, Upgrades and Live Media
    Replies: 0
    Last Post: 20th June 2009, 01:15 AM
  3. Fedora 8 Update Exception
    By hardynet in forum Using Fedora
    Replies: 2
    Last Post: 15th December 2007, 05:32 PM
  4. Fedora 8 Exception during installation
    By LinuxTom in forum Installation, Upgrades and Live Media
    Replies: 4
    Last Post: 18th November 2007, 05:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
[[template footer(Guest)]]