comp.lang.ada
 help / color / mirror / Atom feed
* Exceptions as generic parameters
@ 1987-06-29 13:24 Emery
  1987-07-06 14:41 ` sdl
  0 siblings, 1 reply; 2+ messages in thread
From: Emery @ 1987-06-29 13:24 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1987-07-06 14:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1987-06-29 13:24 Exceptions as generic parameters Emery
1987-07-06 14:41 ` sdl

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