Previous topic |
Ada Home Page |
Index
Safe file opening
procedure open_file (the_file : in out FILE_TYPE) is
filename : string (1..30);
namelen : natural;
begin
PUT ("What file do you want to read? ");
GET_LINE (filename, namelen);
OPEN (FILE => the_file,
NAME => filename(1..namelen),
MODE => IN_FILE);
exception
when STATUS_ERROR =>
PUT_LINE ("The file is already open");
when NAME_ERROR =>
PUT_LINE ("There is no file with that name");
when USE_ERROR =>
PUT_LINE ("The file cannot be read");
when others =>
PUT_LINE ("Unexpected error on opening file");
end open_file;
Previous topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 26 Feb 96