The following exceptions can be raised by input-output operations. They are declared in the package IO_EXCEPTIONS, defined in section 14.5; this package is named in the context clause for each of the three input-output packages. Only outline descriptions are given of the conditions under which NAME_ERROR, USE_ERROR, and DEVICE_ERROR are raised; for full details see Appendix F. If more than one error condition exists, the corresponding exception that appears earliest in the following list is the one that is raised.
The exception STATUS_ERROR is raised by an attempt to operate upon a file that is not open, and by an attempt to open a file that is already open.
The exception MODE_ERROR is raised by an attempt to read from, or test for the end of, a file whose current mode is OUT_FILE, and also by an attempt to write to a file whose current mode is IN_FILE. In the case of TEXT_IO, the exception MODE_ERROR is also raised by specifying a file whose current mode is OUT_FILE in a call of SET_INPUT, SKIP_LINE, END_OF_LINE, SKIP_PAGE, or END_OF_PAGE; and by specifying a file whose current mode is IN_FILE in a call of SET_OUTPUT, SET_LINE_LENGTH, SET_PAGE_LENGTH, LINE_LENGTH, PAGE_LENGTH, NEW_LINE, or NEW_PAGE.
The exception NAME_ERROR is raised by a call of CREATE or OPEN if the string given for the parameter NAME does not allow the identification of an external file. For example, this exception is raised if the string is improper, or, alternatively, if either none or more than one external file corresponds to the string.
The exception USE_ERROR is raised if an operation is attempted that is not possible for reasons that depend on characteristics of the external file. For example, this exception is raised by the procedure CREATE, among other circumstances, if the given mode is OUT_FILE but the form specifies an input only device, if the parameter FORM specifies invalid access rights, or if an external file with the given name already exists and overwriting is not allowed.
The exception DEVICE_ERROR is raised if an input-output operation cannot be completed because of a malfunction of the underlying system.
The exception END_ERROR is raised by an attempt to skip (read past) the end of a file.
The exception DATA_ERROR may be raised by the procedure READ if the element read cannot be interpreted as a value of the required type. This exception is also raised by a procedure GET (defined in the package TEXT_IO) if the input character sequence fails to satisfy the required syntax, or if the value input does not belong to the range of the required type or subtype.
The exception LAYOUT_ERROR is raised (in text input-output) by COL, LINE, or PAGE if the value returned exceeds COUNT'LAST. The exception LAYOUT_ERROR is also raised on output by an attempt to set column or line numbers in excess of specified maximum line or page lengths, respectively (excluding the unbounded cases). It is also raised by an attempt to PUT too many characters to a string.
References: col function, create procedure, end_of_line function, end_of_page function, external file, file, form string, get procedure, in_file, io_exceptions package, line function, line_length function, name string, new_line procedure, new_page procedure, open procedure, out_file, page function, page_length function, put procedure, read procedure, and 14.2.3, set_input procedure, set_line_length, set_page_length, set_output, skip_line procedure, skip_page procedure, text_io package.
Rationale references: 16 Input-Output, 16.6 Exceptions and Renaming
Address any questions or comments to email@example.com.