From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!feeder.xsnews.nl!feeder.news-service.com!tudelft.nl!transit0.news.tiscali.nl!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Class hierarchy of exceptions (Ada, C++) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1111607633.301232.62490@z14g2000cwz.googlegroups.com> <87oed6wvyx.fsf_-_@insalien.org> <1111876424.201726@athnrd02> <874qewvycq.fsf@insalien.org> <1112011700.94455@athnrd02> From: Ludovic Brenta Date: Mon, 28 Mar 2005 14:21:11 +0200 Message-ID: <87zmwoufk8.fsf@insalien.org> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:Wf4UsDtBPYJN4kZN13sw7J7F2XM= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 28 Mar 2005 14:21:19 CEST NNTP-Posting-Host: 83.134.239.98 X-Trace: 1112012479 dreader2.news.tiscali.nl 44076 83.134.239.98:36393 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:10067 comp.lang.c++:47588 comp.realtime:1772 comp.software-eng:5406 Date: 2005-03-28T14:21:19+02:00 List-Id: Ioannis Vranos writes: > So if you like to be as much constrained as possible, I think VB is > much better for this. Or even Logo. Plus it provides a turtle to > help you. Ah yes, embedded, real-time, certified Logo :) Come on. > #include > > > class SomeException: public std::exception > { > const char *errorMessage; > > public: > SomeException(const char *error):errorMessage(error) {} > > const char *what( ) const throw() > { > return errorMessage; > } > }; > > > int main() try ^ Isn't there a missing { here? > { > throw SomeException("Something is wrong!"); > } > > > catch(std::exception &e) > { > std::cerr< } And a missing } here? In which case I don't see any propagation of your exception up the stack, as there is only one stack frame. > C:\c>temp > Something is wrong! > > C:\c> > > > > The exception gets copied as it is propagated up to the stack (with > the use of the copy constructor). I am not a compiler writer either. Since you don't provide a copy constructor, only a shallow copy takes place. Where is the message string allocated, and how do you know it is still accessible when you catch the exception in a location remote from the throw statement? Also, copying the exception once for each stack frame seems quite inefficient to me. I doubt that compiler writers would do that, especially in the general case of C++ where the exception object can be arbitrarily large. -- Ludovic Brenta.