From: sami3079 AT my-deja DOT com Newsgroups: comp.os.msdos.djgpp Subject: Newbie problem with using exceptions Date: Sun, 13 Aug 2000 19:12:39 GMT Organization: Deja.com - Before you buy. Lines: 55 Message-ID: <8n6rv4$gkj$1@nnrp1.deja.com> NNTP-Posting-Host: 195.165.1.13 X-Article-Creation-Date: Sun Aug 13 19:12:39 2000 GMT X-Http-User-Agent: Mozilla/4.7 [en] (Win98; I) X-Http-Proxy: HTTP/1.1 cache.inet.fi[C0A8020D] (The_Hudsucker_Proxy/TRE/3.0.6 [uScMs f p eN:t cCMi p s ]), 1.0 x71.deja.com:80 (Squid/1.1.22) for client 195.165.1.13 X-MyDeja-Info: XMYDJUIDsami3079 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I've programmed some time in C and I'm trying to switch to C++ and I'm having problems with using the exceptions. DJGPP crashes when I try this: /*************************/ class Obj { Obj() { throw 0; } }; int Test () { Obj *o; try { o = new Obj; } catch (...) { return -1; } delete o; return 0; } int main () { if ( Test() != 0 ) printf ( "\nError!" ); return 0; } /*************************/ I know this is poor use of exceptions anyway, but would need this kind of system because when I create objects, I can't otherwise know if there was a problem in constructor. Can anybody give me a hint how this should be done in the right way. Please don't comment the use of printf() in a C++ program... By the way I would also like to know are you guys always freeing up all the allocated memory when your program gets an error, or are you just quitting with exit() or some similar way? Thanks. Sent via Deja.com http://www.deja.com/ Before you buy.