comp.lang.ada
 help / color / mirror / Atom feed
From: emery@MITRE-BEDFORD.ARPA (Emery)
Subject: Exceptions as generic parameters
Date: Mon, 29-Jun-87 09:24:24 EDT	[thread overview]
Date: Mon Jun 29 09:24:24 1987
Message-ID: <8706291324.AA03730@mitre-bedford.ARPA> (raw)


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

             reply	other threads:[~1987-06-29 13:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-06-29 13:24 Emery [this message]
1987-07-06 14:41 ` Exceptions as generic parameters sdl
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox