help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

does g++ 2.95.3 support exceptions?


From: Phil Adams
Subject: does g++ 2.95.3 support exceptions?
Date: Tue, 7 May 2002 09:15:19 -0500

Dereferencing a NULL pointer will cause a segmentation fault (core dump), 
not an exception.   That is why you don't see an exception being thrown in 
your example code.   If you want an exception to be thrown, then throw it 
yourself, like this:

try {
    cout << "About to throw an exception..." << endl;
    throw 1;
}
catch ( ... ) {
   cout << "Caught an exception!" << endl;
}



Phil Adams
WebSphere Development
IBM Austin, TX
phil_adams@us.ibm.com
(512) 838-6702 (tie 678)

----- Forwarded by Phil Adams/Austin/IBM on 05/07/2002 09:12 AM -----


Vijay Patil <vijaypatil78@yahoo.com>
Sent by: help-gplusplus-admin@gnu.org
05/07/2002 07:43 AM

 
        To:     help-gplusplus@gnu.org
        cc: 
        Subject:        does g++ 2.95.3 support exceptions?

 

Hello 
      i'm using g++ 2.95.3 both on Linux and Sun
Solaris and tried following code

#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
        try
        {
                cout<<"Before throw"<<endl;
                char* ptr=0;
                cout<<"after throw "<<*ptr<<endl;
        }
        catch(...)
        {
                cout<<"In side catch"<<endl;
        }
        return(0);
} 

and compiled with this command

g++ -fexceptions test.cpp

when i run a.out i get segmentation fault 
why is it so inspite of enabling exceptions ? it
should go in catch block

does any one how to enable exceptions ??

Thanks and Regards
Vijay Patil



__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

_______________________________________________
Help-gplusplus mailing list
Help-gplusplus@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gplusplus






reply via email to

[Prev in Thread] Current Thread [Next in Thread]