comp.lang.ada
 help / color / mirror / Atom feed
From: Sergey Koshcheyev <serko84@hotmail.com>
Subject: Re: I/O - exception handling
Date: Tue, 27 May 2003 09:21:28 +0200
Date: 2003-05-27T09:21:28+02:00	[thread overview]
Message-ID: <bav3ln$n74$1@ns.felk.cvut.cz> (raw)
In-Reply-To: <bauf7t$tei$1@ns.omskelecom.ru>

Anisimkov wrote:
> "Sergey Koshcheyev" <serko84@hotmail.com> wrote in message
> Your should not catch exception on the Close, becouse Ada95 RM A.8.2 File
> Management
> says "The exception Status_Error is propagated if the given file is not
> open.". So if file is Open, you do not need to wait exception. I thing GNAT
> spetsific Ada.Strings.Unbounded.Text_IO.Close have the same behavior. If you
> are want to catch exception anyway (for example you are using any other IO
> implementation.) you can make local procedure inside of Read_Something.

(The File_Type, Open and Close that were used in my example are from 
Ada.Text_IO, only Get_Line comes from A.S.U.Text_IO, and that's a 
function, not a procedure as I used it originally. But the example was 
only meant to illustrate, I'm sorry for the confusion.)

I've seen the paragraph, but I don't know if it can be read as "the only 
exception that may be propagated from Close is Status_Error, and that 
only if the file was not open" - the clause doesn't give me any such 
guarantees.

For example, I think Close is legally allowed to raise Device_Error, or 
even Use_Error.

>  begin
>     Open (File, Name => "test.txt", Mode => In_File);
>     Get_Line (File, S1);
>     Get_Line (File, S2);
>     Close_File;
> 
>  exception
>     when others =>
>          Close_File;
> end Read_Something;

This closes the file twice, as does the example below - something I 
don't like.

> But, in my point of view, it is bad practice to suppress exception
> completely. I prefer to know about errors in program execution. If we do not
> suppress exception, code become simplier. We need to catch exceptions only in
> Get_Line routines. Exceptions in Open routine do not need to be catched
> becouse we do not need to close not opened file. For the Ada semantic File we
> can write just.

I hereby promise I won't ignore the I/O exceptions in real code (or at 
least I'll try not to :-)), that example was just an example.

> exception
>     when Device_Error | Data_Error =>
>           --  Device_Error and Data_Error could be raised only on IO
> operations
>           --  So the file is already opened and we do not need to check is
> file open
>           --  before close.

But Open and Close may raise Device_Error too?

>           Close_File (File);

Again, you have to remember to close the file in two places.

>           raise;
> end Read_Something;

Sergey.




  reply	other threads:[~2003-05-27  7:21 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-26 13:05 I/O - exception handling Sergey Koshcheyev
2003-05-26 13:33 ` Preben Randhol
2003-05-26 14:11   ` Sergey Koshcheyev
2003-05-26 14:29     ` Preben Randhol
2003-05-26 14:31       ` Preben Randhol
2003-05-26 14:39       ` Sergey Koshcheyev
2003-05-26 16:57         ` Preben Randhol
2003-05-26 17:48           ` Sergey Koshcheyev
2003-05-26 18:08             ` Preben Randhol
2003-05-26 18:48               ` Sergey Koshcheyev
2003-05-27  1:24                 ` Hyman Rosen
2003-05-27  2:20                   ` Larry Kilgallen
2003-05-27  2:38                     ` Hyman Rosen
2003-05-27 16:17                       ` Warren W. Gay VE3WWG
2003-05-27 19:40                         ` Hyman Rosen
2003-05-27 20:18                           ` Warren W. Gay VE3WWG
2003-05-27 10:31                     ` Larry Kilgallen
2003-05-27 21:43                       ` Hyman Rosen
2003-05-27  5:33           ` Robert I. Eachus
2003-05-27 13:53             ` Preben Randhol
2003-05-27 12:01           ` Lutz Donnerhacke
2003-05-26 14:12   ` Simon Wright
2003-05-26 14:24     ` Preben Randhol
2003-05-26 14:52 ` Jean-Pierre Rosen
2003-05-26 15:26   ` Sergey Koshcheyev
2003-05-26 15:45 ` Hyman Rosen
2003-05-26 16:25   ` Sergey Koshcheyev
2003-05-27  1:35     ` Hyman Rosen
2003-05-28 21:47       ` Robert A Duff
2003-05-26 16:31 ` Steve
2003-05-27  2:36 ` Anisimkov
2003-05-27  7:21   ` Sergey Koshcheyev [this message]
2003-05-27 13:47     ` Preben Randhol
2003-05-27 19:01       ` Sergey Koshcheyev
2003-05-27 16:50     ` Dmitriy Anisimkov
2003-05-27 18:11       ` Ludovic Brenta
2003-05-28  1:27   ` Jeffrey Carter
2003-05-28  7:33     ` Sergey Koshcheyev
2003-05-28  9:08       ` Preben Randhol
2003-05-28 18:07         ` Randy Brukardt
2003-05-28 22:51           ` Robert I. Eachus
2003-05-29  2:03             ` Jeffrey Carter
2003-05-29  8:39               ` Manuel Collado
2003-05-30  6:56           ` Preben Randhol
2003-05-30  9:33             ` Larry Kilgallen
2003-05-30 11:13               ` Preben Randhol
2003-05-30 11:39                 ` Larry Kilgallen
2003-05-30 11:41                   ` Preben Randhol
2003-05-30 19:51                 ` Randy Brukardt
2003-06-01 16:08                   ` Robert I. Eachus
2003-06-03  0:18                     ` Randy Brukardt
2003-06-03  4:16                       ` Robert I. Eachus
     [not found] ` <slrnbd6m69.vh.lutz@taranis.iks-jena.de>
2003-05-27 14:06   ` Preben Randhol
2003-05-27 15:59     ` Lutz Donnerhacke
2003-05-27 19:05   ` Sergey Koshcheyev
2003-05-27 19:32     ` Larry Kilgallen
replies disabled

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