c++11 - C++: error: exception handling disabled, use -fexceptions to enable -


i trying compile simple code -fno-exceptions flag. giving error.

please let me know how suppress this. using gcc version 4.6.3

code

#include <iostream> using namespace std; int main () {   try   {     throw 20;   }   catch (int e)   {     cout << "an exception occurred. exception nr. " << e << '\n';   }   return 0; } 

log

> g++ throw.cc -o out -fno-exceptions throw.cc: in function ‘int main()’: throw.cc:10:11: error: exception handling disabled, use -fexceptions enable throw.cc:14:56: error: ‘e’ not declared in scope 

edit

i have client code have lot throws this. have integrate in project , can't control compilation flags build(which come config has -fno-exceptions enabled). wanted quick work around can suggest.

edit

i found workaround see below answer.

you cannot use -fno-exceptions flag program, use exceptions (try/catch/throw).

quote gcc manual

before detailing library support -fno-exceptions, first passing note on things lost when flag used: break exceptions trying pass through code compiled -fno-exceptions whether or not code has try or catch constructs. if might have code throws, shouldn't use -fno-exceptions. if have code uses try or catch, shouldn't use -fno-exceptions.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -