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,eee47022b0e39dbb X-Google-Attributes: gid103376,public From: kilgallen@eisner.decus.org (Larry Kilgallen) Subject: Re: Exception problem Date: 1997/02/24 Message-ID: <1997Feb24.124153.1@eisner>#1/1 X-Deja-AN: 221108455 X-Nntp-Posting-Host: eisner.decus.org References: <330A0D25.313@fs2.assist.uci.edu> <3311BFC4.7576@fs2.assist.uci.edu> X-Nntp-Posting-User: KILGALLEN X-Trace: 856806117/19470 Organization: LJK Software Newsgroups: comp.lang.ada Date: 1997-02-24T00:00:00+00:00 List-Id: 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. In this particular case, the decision should probably based not on the fact that typing wrong characters may or may not be "normal" for your user population, but rather on the fact that anything taking keyboard input from humans has no hope of running fast enough to waste many cycles anyway. Considering that you may type out an error message or something similar (I forget the original code) in the wrong keystroke case, the overhead of depending on exceptions might be lost in the noise of other activity anyway. Besides, somebody ought to be testing the exception handling of compilers on a regular basis -- I nominate you :-) Larry Kilgallen