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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,eee47022b0e39dbb X-Google-Attributes: gid103376,public From: Larry Coon Subject: Re: Exception problem Date: 1997/02/24 Message-ID: <3311FD32.2DDA@fs2.assist.uci.edu>#1/1 X-Deja-AN: 221143022 References: <330A0D25.313@fs2.assist.uci.edu> <3311BFC4.7576@fs2.assist.uci.edu> <1997Feb24.124153.1@eisner> Content-Type: text/plain; charset=us-ascii Organization: University of California Mime-Version: 1.0 Reply-To: larry@fs2.assist.uci.edu Newsgroups: comp.lang.ada X-Mailer: Mozilla 3.0 (Win95; I) Date: 1997-02-24T00:00:00+00:00 List-Id: Larry Kilgallen wrote: > > In article <3311BFC4.7576@fs2.assist.uci.edu>, Larry Coon writes: > > > By the way, that brings up another question....that of when it's > > appropriate to use exceptions. In C++, for example, you wouldn't want > > to throw an exception because your number should be positive and you got > > a negative. In C++, you're using an int to represent this number, and > > for an int to be -3 is not an exceptional condition. However, in Ada > > subtypes and derived types allow you to declare integers for which -3 > > truly is an exceptional condition, making it very appropriate to raise > > (see, I even got the terminology right!) an exception. > > > > Writing that code almost made me feel guilty for using exceptions the > > wrong way, and I wanted to make sure I'm thinking about them in the > > right way in Ada. > > Implementations are likely to use hardware exception mechanisms and > other non-speed-optimized techniques to implement something called > an "exception" in any language. Thus you should not count on using > exceptions as a "normal" part of processing which is supposed to run > efficiently. My concern is not so much related to performance as it is to the general axiom (at least in C++) that exception handling is meant for truly exceptional events, and that invalid input just doesn't qualify. The general rule in C++ is that exception handling shouldn't be used for input validation. However, given the more powerful type definition capabilities of Ada, invalid input can create exceptional conditions that wouldn't be exceptional in C++. So I guess my question is, does that make it okay to use exception handling for input validation in Ada? Or, in cases such as keyboard input, should I go on the premise that the user is inputing using a keyboard, keyboards produce characters, and character input is what should be expected. Therefore, the correct thing to do is to accept character input, validate it, and then if it's okay convert it to the appropriate type. Granted, doing it the first way is a lot easier.... Larry Coon University of California larry@fs2.assist.uci.edu