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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,820de86ed0dafb8a X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: Help Me Please :) Date: 2000/03/19 Message-ID: #1/1 X-Deja-AN: 599654682 Sender: bobduff@world.std.com (Robert A Duff) References: <89rlvr$gn9$1@nntp3.atl.mindspring.net> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-03-19T00:00:00+00:00 List-Id: "James S. Rogers" writes: > Have you ever used exceptions in C++? No. The last time I used C++ (some years ago), most compilers did not support exceptions. The closest I could get was reading about them in Stroustrup's book. But I have used exceptions in other languages that define exceptions as first-class objects. >...Very few people do. > The problem arises from the fact that exceptions are first class objects. I don't understand this problem. Perhaps you could give an example? Is the problem you're talking about C++-specific, or are you claiming it's a fundamental problem with the idea of exceptions-as-objects? One problem I see with C++ exceptions is that anything can be an exception -- you can throw a string or an int or whatever. I would prefer to have a distinguished exception class, and then you could define new exceptions by subclassing that. Several other languages that have first-class exceptions do exactly that. But this seems like a minor issue. > In C++ you cannot "catch" an exception without knowing its type. This means > that you must have exquisite coupling with all your dependent compilation > units > to use exceptions reliably. This coupling requirement works strongly against > encapsulation and modularity. Again, I don't get it. Of course you can't catch an exception without knowing its type. Just like in Ada you can't handle an exception without knowing its name. I don't see how that breaks encapsulation and modularity. > The only way around this is to declare a single exception type for all > exceptions > generated by an application. This leaves you in the same position as you are > in Ada. Of course, the problem with this solution for C++ is that you will > probably use > class libraries, which, if they use exceptions at all, will probably not > conform to the > exception class chosen by your team. If this is the case, then you are in a > much > worse situation than if you used Ada. - Bob