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.1 required=5.0 tests=BAYES_40,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ll-xn!mit-eddie!genrad!decvax!ucbvax!MITRE-BEDFORD.ARPA!emery From: emery@MITRE-BEDFORD.ARPA (Emery) Newsgroups: comp.lang.ada Subject: Exceptions as generic parameters Message-ID: <8706291324.AA03730@mitre-bedford.ARPA> Date: Mon, 29-Jun-87 09:24:24 EDT Article-I.D.: mitre-be.8706291324.AA03730 Posted: Mon Jun 29 09:24:24 1987 Date-Received: Sat, 4-Jul-87 05:05:48 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet List-Id: While we are on the topic of language 'deficiencies', here's one of my peeves: I would like to pass exceptions to generics. Consider the following: generic type t is private; with procedure try_to_print_t (a_t : t); -- what happens if try_to_print raises an exception? -- in particular, I know that there may be problems printing t, whatever -- t may be. If there is a 'printing' error, I would like to recover -- from it separately from other errors (such as program_error...) procedure print_with_caption (a_t : t; caption : string); Here are two 'candidates' for the generic: package one is type t is string(1..20); procedure print_t (a_t : t); non_printing_char_in_string: exception; end one; package two is type t is (red, green, blue, black, white); procedure set_color_attribute (to_color : t); not_a_color_terminal : exception; end two; Now, in the body of generic print_with_caption, I would like to handle the an error in printing separately than all other errors, i.e. I would like to do some real error recovery. (In this case, I will probably ignore printing errors, but re-raise other errors). Either the generic unit must 'with' all possible instantiators, and do 'case analysis' on the possible exceptions, or it must use the 'when others' clause, and hope for the best. Here's what I would like to say: generic type t is private; with procedure try_to_print_t (a_t : t); error_printing_t : exception; -- exception raised in try_to_print_t procedure print_with_caption (a_t : t; caption : string); Types, objects and subprograms can be passed to generics, why not exceptions? dave emery emery@mitre-bedford.arpa