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,436ac666600e5ab3 X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: Re: Exception Handling Date: 2000/06/01 Message-ID: #1/1 X-Deja-AN: 630015221 References: <3HCY4.29157$sB3.10828@news.indigo.ie> <3933DAF3.35F40B3A@utech.net> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Complaints-To: usenet@news.huji.ac.il X-Trace: news.huji.ac.il 959886990 11277 132.64.178.45 (1 Jun 2000 19:16:30 GMT) Organization: The Hebrew University of Jerusalem Mime-Version: 1.0 NNTP-Posting-Date: 1 Jun 2000 19:16:30 GMT Newsgroups: comp.lang.ada Date: 2000-06-01T19:16:30+00:00 List-Id: On 1 Jun 2000, Preben Randhol wrote: |Would it be OK to trap an erronious entry (like "2.3W-4") with an |exception or would you make an extra check before trying to convert the |string to a float (or the appropriate class). | |The reason I'm asking is that there seems to be two "camps" those who |use exceptions extensivly and those who use it far less. I'm trying to |find the border when and when not to use exceptions. | The way I see it, it's like this. I try not to use exceptions to guide the flow inside a routine (like "goto") unless there is a good reason to do so (e..g, if there is convergence with an exception raised by a service routine etc.). So if I am doing a translation myself (char by char) I'd probably use an "if" (though I am not 100% sue, since you should always check the complexity things add to your code. If it is simply if s(i) is digits ... elsif upcase(s(i))='E' ... else ERROR than I can live with that). If I can use another routine to do the conversion, I'd assume the routine would communicate the presence of an error with an exception. Since I assume the input routine is an input routine, and thus wrog input is problematic, I'd think the input routine itself RAISES an exception. (This is the other side of the coin...) You can see an possible approach to these issues (though not exactly matching your scenario) in my Safe_Io package, and my Generic_Menu routine. Both on AdaPower. Ehud Lamm mslamm@mscc.huji.ac.il http://purl.oclc.org/NET/ehudlamm <== My home on the web Check it out and subscribe to the E-List- for interesting essays and more!