Fedora Linux Support Community & Resources Center
  #1  
Old 8th September 2009, 05:08 PM
EmbeddedTwix Offline
Registered User
 
Join Date: Aug 2009
Location: Switzerland
Posts: 14
linuxfedorafirefox
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
Reply With Quote
  #2  
Old 8th September 2009, 11:47 PM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,075
linuxfirefox
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.
Reply With Quote
  #3  
Old 9th September 2009, 10:21 AM
EmbeddedTwix Offline
Registered User
 
Join Date: Aug 2009
Location: Switzerland
Posts: 14
linuxfedorafirefox
Hi Markkuk,

Thanks for the answer.

My C++ book is that bad!

Regards,
RL
Reply With Quote
Reply

Tags
exception, fedora, handling

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


Current GMT-time: 22:16 (Saturday, 30-08-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat