WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: gcc exception handling  (Read 6639 times)

Offline robc

  • Sr. Member
  • ****
  • Posts: 447
gcc exception handling
« on: July 15, 2009, 08:06:13 PM »
Has anyone been able to get the exception handling to work?
Here is a simple test I wrote:
Code: [Select]
// testing.cpp
#include <iostream>
using namespace std;

int main() {
  int i;
  {
    try {
      printf("Input: ");
      cin >> i;
      throw i;
      printf("No exception caught.\n");
    } catch (...) {
      printf("Caught exception.\n");
    }
  }
}
The exception is not handled, instead it goes straight to terminate.

This was compiled with: g++ -x c++ -fexceptions -o testing testing.cpp
"Never give up! Never surrender!" - Commander Peter Quincy Taggart

"Make it so." - Captain Picard

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: gcc exception handling
« Reply #1 on: July 15, 2009, 09:54:01 PM »
Apparently so, It works fine in TC 1.4.3.
10+ Years Contributing to Linux Open Source Projects.

Offline robc

  • Sr. Member
  • ****
  • Posts: 447
Re: gcc exception handling
« Reply #2 on: July 16, 2009, 01:14:18 PM »
is this because the CXXFLAGS are set to this in the TC 2.X gcc?
Code: [Select]
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions"
"Never give up! Never surrender!" - Commander Peter Quincy Taggart

"Make it so." - Captain Picard

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14851
Re: gcc exception handling
« Reply #3 on: July 16, 2009, 02:19:04 PM »
According to my notes, this was how gcc was compiled...

Offline danniel

  • Newbie
  • *
  • Posts: 6
Re: gcc exception handling
« Reply #4 on: July 19, 2009, 05:42:04 AM »
Is it possible that this would be the reason why that happens http://forum.tinycorelinux.net/index.php?topic=1262.0 ; according with my investigations:  http://lists.busybox.net/pipermail/uclibc/2006-June/036553.html  .

Any elegant solution?

Congrats for this great distro to all of you.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: gcc exception handling
« Reply #5 on: July 20, 2009, 07:24:22 PM »
I'm connecting the dots here ...
http://forum.tinycorelinux.net/index.php?topic=1784.0

I am confused. Does this mean that anything we compile in 2.x cannot use exceptions? Is it true that this behavior cannot be avoided with the "-fexceptions" option?

Offline danniel

  • Newbie
  • *
  • Posts: 6
Re: gcc exception handling
« Reply #6 on: August 05, 2009, 04:34:51 AM »
Thanks, Juanito for the new binaries of gcc 4.4.0 .
 Now it is possible to compile and run things that fail before in TC2.x (but not in TC1.4.3), as indicated in above posts (v.g. amsn).
The only issue is that as TinyCore 2.x is not build with this release, it is necessary to install as dependence. Until the definitive solution, this is a good approach.
Thanks again.

Offline helander

  • Full Member
  • ***
  • Posts: 183
Re: gcc exception handling
« Reply #7 on: February 04, 2010, 01:59:48 PM »
Could someone provide a summary of what is needed in order to build and run programs that rely on exceptions?
  • Extensions that must be installed when building.
  • Extensions that must NOT be installed when building
  • Extensions that must be installed when running the program
  • Extensions that must NOT be installed when running the program

If the program depdends (dynamically links) to libraries in other extensions, do these extensions also have to be built with exceptions enabled?

Kind Regards

/Lars

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14851
Re: gcc exception handling
« Reply #8 on: February 12, 2010, 08:25:33 AM »
This was compiled with: g++ -x c++ -fexceptions -o testing testing.cpp

When I try, I get this:
Code: [Select]
$ g++ -x c++ -fexceptions -o testing testing.cpp
testing.cpp: In function 'int main()':
testing.cpp:9: error: 'printf' was not declared in this scope
testing.cpp:14: error: 'printf' was not declared in this scope

..but this works:
Code: [Select]
// testing.cpp
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int i;
  {
    try {
      printf("Input: ");
      cin >> i;
      throw i;
      printf("No exception caught.\n");
    } catch (...) {
      printf("Caught exception.\n");
    }
  }
}
« Last Edit: February 12, 2010, 08:28:44 AM by Juanito »